diff --git a/dist/components/__tests__/entity-test.js b/dist/components/__tests__/entity-test.js index 71238a5..c6aa2e2 100644 --- a/dist/components/__tests__/entity-test.js +++ b/dist/components/__tests__/entity-test.js @@ -106,4 +106,38 @@ describe('Entity', function () { expect(entity.getEntity()).toBeDefined(); }); }); + + describe('binding', function () { + + it('keeps the listeners separated', function () { + window.google.maps.Entity = function () { + return { + setMap: jest.genMockFunction(), + setOptions: jest.genMockFunction() + }; + }; + var Parent = React.createClass({ + displayName: 'Parent', + + getInitialState: function getInitialState() { + return { + show: true + }; + }, + render: function render() { + return React.createElement( + 'div', + null, + React.createElement(Entity, { ref: 'child', onClick: jest.genMockFunction() }), + this.state.show && React.createElement(Entity, { onClick: jest.genMockFunction() }) + ); + } + }); + var parent = TestUtils.renderIntoDocument(React.createElement(Parent, null)); + parent.setState({ + show: false + }); + expect(parent.refs.child.listeners.length).toBe(1); + }); + }); }); \ No newline at end of file diff --git a/dist/mixins/listener.js b/dist/mixins/listener.js index e219211..fba9d5d 100644 --- a/dist/mixins/listener.js +++ b/dist/mixins/listener.js @@ -6,20 +6,21 @@ Object.defineProperty(exports, "__esModule", { var Listener = { - listeners: [], - addListeners: function addListeners(entity, events) { for (var prop in this.props) { if (this.props.hasOwnProperty(prop) && events[prop]) { var addListener = google.maps.event.addListener; var listener = addListener(entity, events[prop], this.props[prop]); + if (!this.listeners) { + this.listeners = []; + } this.listeners.push(listener); } } }, removeListeners: function removeListeners() { - if (window.google) { + if (window.google && this.listeners) { this.listeners.forEach(function (listener) { google.maps.event.removeListener(listener); }); diff --git a/package.json b/package.json index 6980431..6b3e14c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-gmaps", - "version": "1.2.1", + "version": "1.2.2", "description": "A Google Maps component for React.js", "main": "dist/index.js", "scripts": {