Skip to content

Commit

Permalink
version 1.2.2 - closes #32
Browse files Browse the repository at this point in the history
  • Loading branch information
MicheleBertoli committed Jan 7, 2016
1 parent 69edcbd commit c35c56a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
34 changes: 34 additions & 0 deletions dist/components/__tests__/entity-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
7 changes: 4 additions & 3 deletions dist/mixins/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit c35c56a

Please sign in to comment.