diff --git a/dist/components/__tests__/entity-test.js b/dist/components/__tests__/entity-test.js index c6aa2e2..407f5b5 100644 --- a/dist/components/__tests__/entity-test.js +++ b/dist/components/__tests__/entity-test.js @@ -1,6 +1,7 @@ 'use strict'; jest.dontMock('../../mixins/listener'); +jest.dontMock('../../utils/compare-props'); jest.dontMock('../entity'); describe('Entity', function () { @@ -72,7 +73,9 @@ describe('Entity', function () { describe('updating', function () { - it('calls `setOptions` when receive new props', function () { + var parent = undefined; + + beforeEach(function () { window.google.maps.Entity = function () { return { setOptions: jest.genMockFunction() @@ -83,19 +86,31 @@ describe('Entity', function () { getInitialState: function getInitialState() { return { - content: '1' + prop: '1' }; }, render: function render() { - return React.createElement(Entity, { ref: 'child' }); + var prop = this.state.prop; + + return React.createElement(Entity, { ref: 'child', prop: prop }); } }); - var parent = TestUtils.renderIntoDocument(React.createElement(Parent, null)); + parent = TestUtils.renderIntoDocument(React.createElement(Parent, null)); + }); + + it('calls `setOptions` when receive new props', function () { parent.setState({ - content: '2' + prop: '2' }); expect(parent.refs.child.entity.setOptions).toBeCalled(); }); + + it('does not call `setOptions` when props are the same', function () { + parent.setState({ + prop: '1' + }); + expect(parent.refs.child.entity.setOptions).not.toBeCalled(); + }); }); describe('getEntity', function () { diff --git a/dist/components/entity.js b/dist/components/entity.js index 37bf9fd..7284c44 100644 --- a/dist/components/entity.js +++ b/dist/components/entity.js @@ -18,6 +18,10 @@ var _mixinsListener = require('../mixins/listener'); var _mixinsListener2 = _interopRequireDefault(_mixinsListener); +var _utilsCompareProps = require('../utils/compare-props'); + +var _utilsCompareProps2 = _interopRequireDefault(_utilsCompareProps); + exports['default'] = function (name, latLngProp, events) { return _react2['default'].createClass({ @@ -32,8 +36,10 @@ exports['default'] = function (name, latLngProp, events) { }, componentWillReceiveProps: function componentWillReceiveProps(nextProps) { - var options = this.getOptions(nextProps); - this.entity.setOptions(options); + if (!(0, _utilsCompareProps2['default'])(this.props, nextProps)) { + var options = this.getOptions(nextProps); + this.entity.setOptions(options); + } }, componentWillUnmount: function componentWillUnmount() { diff --git a/package.json b/package.json index 4589192..7abb141 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-gmaps", - "version": "1.4.1", + "version": "1.4.2", "description": "A Google Maps component for React.js", "main": "dist/index.js", "scripts": {