Skip to content

Commit c35c56a

Browse files
version 1.2.2 - closes #32
1 parent 69edcbd commit c35c56a

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

dist/components/__tests__/entity-test.js

+34
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,38 @@ describe('Entity', function () {
106106
expect(entity.getEntity()).toBeDefined();
107107
});
108108
});
109+
110+
describe('binding', function () {
111+
112+
it('keeps the listeners separated', function () {
113+
window.google.maps.Entity = function () {
114+
return {
115+
setMap: jest.genMockFunction(),
116+
setOptions: jest.genMockFunction()
117+
};
118+
};
119+
var Parent = React.createClass({
120+
displayName: 'Parent',
121+
122+
getInitialState: function getInitialState() {
123+
return {
124+
show: true
125+
};
126+
},
127+
render: function render() {
128+
return React.createElement(
129+
'div',
130+
null,
131+
React.createElement(Entity, { ref: 'child', onClick: jest.genMockFunction() }),
132+
this.state.show && React.createElement(Entity, { onClick: jest.genMockFunction() })
133+
);
134+
}
135+
});
136+
var parent = TestUtils.renderIntoDocument(React.createElement(Parent, null));
137+
parent.setState({
138+
show: false
139+
});
140+
expect(parent.refs.child.listeners.length).toBe(1);
141+
});
142+
});
109143
});

dist/mixins/listener.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ Object.defineProperty(exports, "__esModule", {
66

77
var Listener = {
88

9-
listeners: [],
10-
119
addListeners: function addListeners(entity, events) {
1210
for (var prop in this.props) {
1311
if (this.props.hasOwnProperty(prop) && events[prop]) {
1412
var addListener = google.maps.event.addListener;
1513
var listener = addListener(entity, events[prop], this.props[prop]);
14+
if (!this.listeners) {
15+
this.listeners = [];
16+
}
1617
this.listeners.push(listener);
1718
}
1819
}
1920
},
2021

2122
removeListeners: function removeListeners() {
22-
if (window.google) {
23+
if (window.google && this.listeners) {
2324
this.listeners.forEach(function (listener) {
2425
google.maps.event.removeListener(listener);
2526
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-gmaps",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "A Google Maps component for React.js",
55
"main": "dist/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)