react-google-maps-sep
Version:
React.js Google Maps integration component
47 lines (36 loc) • 1.25 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = eventHandlerCreator;
var _react = require("react");
function groupToUpperCase(match, group) {
return group.toUpperCase();
}
function toOnEventName(rawName) {
return "on" + rawName.replace(/^(.)/, groupToUpperCase).replace(/_(.)/g, groupToUpperCase);
}
function eventHandlerCreator(rawNameList) {
var eventPropTypes = {};
var onEventNameByRawName = {};
rawNameList.forEach(function (rawName) {
var onEventName = toOnEventName(rawName);
eventPropTypes[onEventName] = _react.PropTypes.func;
onEventNameByRawName[rawName] = onEventName;
});
function registerEvents(event, props, googleMapInstance) {
var registered = rawNameList.reduce(function (acc, rawName) {
var onEventName = onEventNameByRawName[rawName];
if (Object.prototype.hasOwnProperty.call(props, onEventName)) {
acc.push(event.addListener(googleMapInstance, rawName, props[onEventName]));
}
return acc;
}, []);
return registered.forEach.bind(registered, event.removeListener, event);
}
return {
eventPropTypes: eventPropTypes,
registerEvents: registerEvents
};
}
module.exports = exports["default"];
;