Skip to content

Commit

Permalink
version 1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MicheleBertoli committed Feb 16, 2016
1 parent faa8a7f commit 794d4b3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
25 changes: 20 additions & 5 deletions dist/components/__tests__/entity-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

jest.dontMock('../../mixins/listener');
jest.dontMock('../../utils/compare-props');
jest.dontMock('../entity');

describe('Entity', function () {
Expand Down Expand Up @@ -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()
Expand All @@ -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 () {
Expand Down
10 changes: 8 additions & 2 deletions dist/components/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({

Expand All @@ -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() {
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.4.1",
"version": "1.4.2",
"description": "A Google Maps component for React.js",
"main": "dist/index.js",
"scripts": {
Expand Down

0 comments on commit 794d4b3

Please sign in to comment.