UNPKG

react-google-maps-sep

Version:
83 lines (67 loc) 2.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = componentLifecycleDecorator; function componentLifecycleDecorator(_ref) { var registerEvents = _ref.registerEvents; var instanceMethodName = _ref.instanceMethodName; var updaters = _ref.updaters; // This modify the Component.prototype directly return function (Component) { function register() { this._unregisterEvents = registerEvents(google.maps.event, this.props, this[instanceMethodName]()); } function unregister() { this._unregisterEvents(); this._unregisterEvents = null; } function noop() {} // Stash component's own lifecycle methods to be invoked later var componentDidMount = Component.prototype.hasOwnProperty("componentDidMount") ? Component.prototype.componentDidMount : noop; var componentDidUpdate = Component.prototype.hasOwnProperty("componentDidUpdate") ? Component.prototype.componentDidUpdate : noop; var componentWillUnmount = Component.prototype.hasOwnProperty("componentWillUnmount") ? Component.prototype.componentWillUnmount : noop; Object.defineProperty(Component.prototype, "componentDidMount", { enumerable: false, configurable: true, writable: true, value: function value() { // Hook into client's implementation, if it has any componentDidMount.call(this); register.call(this); } }); Object.defineProperty(Component.prototype, "componentDidUpdate", { enumerable: false, configurable: true, writable: true, value: function value(prevProps) { unregister.call(this); for (var _name in updaters) { if (Object.prototype.hasOwnProperty.call(this.props, _name)) { updaters[_name](this.props[_name], this); } } // Hook into client's implementation, if it has any componentDidUpdate.call(this, prevProps); register.call(this); } }); Object.defineProperty(Component.prototype, "componentWillUnmount", { enumerable: false, configurable: true, writable: true, value: function value() { // Hook into client's implementation, if it has any componentWillUnmount.call(this); unregister.call(this); var instance = this[instanceMethodName](); if ("setMap" in instance) { instance.setMap(null); } } }); return Component; }; } module.exports = exports["default"];