Skip to content

Commit f167016

Browse files
committed
Fix unnecessary marker re-render
1 parent f1e1200 commit f167016

File tree

5 files changed

+2884
-9987
lines changed

5 files changed

+2884
-9987
lines changed

Diff for: dist/components/Marker.js

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
(function (global, factory) {
22
if (typeof define === "function" && define.amd) {
3-
define(['exports', 'react', 'prop-types', '../lib/String'], factory);
3+
define(["exports", "react", "prop-types", "lodash", "../lib/String"], factory);
44
} else if (typeof exports !== "undefined") {
5-
factory(exports, require('react'), require('prop-types'), require('../lib/String'));
5+
factory(exports, require("react"), require("prop-types"), require("lodash"), require("../lib/String"));
66
} else {
77
var mod = {
88
exports: {}
99
};
10-
factory(mod.exports, global.react, global.propTypes, global.String);
10+
factory(mod.exports, global.react, global.propTypes, global.lodash, global.String);
1111
global.Marker = mod.exports;
1212
}
13-
})(this, function (exports, _react, _propTypes, _String) {
14-
'use strict';
13+
})(this, function (exports, _react, _propTypes, _lodash, _String) {
14+
"use strict";
1515

1616
Object.defineProperty(exports, "__esModule", {
1717
value: true
@@ -102,7 +102,7 @@
102102
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
103103
}
104104

105-
var evtNames = ['click', 'dblclick', 'dragend', 'mousedown', 'mouseout', 'mouseover', 'mouseup', 'recenter'];
105+
var evtNames = ["click", "dblclick", "dragend", "mousedown", "mouseout", "mouseover", "mouseup", "recenter"];
106106

107107
var wrappedPromise = function wrappedPromise() {
108108
var wrappedPromise = {},
@@ -127,30 +127,30 @@
127127
}
128128

129129
_createClass(Marker, [{
130-
key: 'componentDidMount',
130+
key: "componentDidMount",
131131
value: function componentDidMount() {
132132
this.markerPromise = wrappedPromise();
133133
this.renderMarker();
134134
}
135135
}, {
136-
key: 'componentDidUpdate',
136+
key: "componentDidUpdate",
137137
value: function componentDidUpdate(prevProps) {
138-
if (this.props.map !== prevProps.map || this.props.position !== prevProps.position || this.props.icon !== prevProps.icon) {
138+
if (this.props.map !== prevProps.map || !(0, _lodash.isEqual)(this.props.position, prevProps.position) || !(0, _lodash.isEqual)(this.props.icon, prevProps.icon)) {
139139
if (this.marker) {
140140
this.marker.setMap(null);
141141
}
142142
this.renderMarker();
143143
}
144144
}
145145
}, {
146-
key: 'componentWillUnmount',
146+
key: "componentWillUnmount",
147147
value: function componentWillUnmount() {
148148
if (this.marker) {
149149
this.marker.setMap(null);
150150
}
151151
}
152152
}, {
153-
key: 'renderMarker',
153+
key: "renderMarker",
154154
value: function renderMarker() {
155155
var _this2 = this;
156156

@@ -163,7 +163,7 @@
163163
label = _props.label,
164164
draggable = _props.draggable,
165165
title = _props.title,
166-
props = _objectWithoutProperties(_props, ['map', 'google', 'position', 'mapCenter', 'icon', 'label', 'draggable', 'title']);
166+
props = _objectWithoutProperties(_props, ["map", "google", "position", "mapCenter", "icon", "label", "draggable", "title"]);
167167

168168
if (!google) {
169169
return null;
@@ -191,31 +191,33 @@
191191
this.markerPromise.resolve(this.marker);
192192
}
193193
}, {
194-
key: 'getMarker',
194+
key: "getMarker",
195195
value: function getMarker() {
196196
return this.markerPromise;
197197
}
198198
}, {
199-
key: 'handleEvent',
199+
key: "handleEvent",
200200
value: function handleEvent(evt) {
201201
var _this3 = this;
202202

203203
return function (e) {
204-
var evtName = 'on' + (0, _String.camelize)(evt);
204+
var evtName = "on" + (0, _String.camelize)(evt);
205205
if (_this3.props[evtName]) {
206206
_this3.props[evtName](_this3.props, _this3.marker, e);
207207
}
208208
};
209209
}
210210
}, {
211-
key: 'render',
211+
key: "render",
212212
value: function render() {
213213
return _react2.default.createElement(
214214
_react.Fragment,
215215
null,
216-
this.props.children && this.marker ? _react2.default.Children.only(_react2.default.cloneElement(this.props.children, { marker: this.marker,
216+
this.props.children && this.marker ? _react2.default.Children.only(_react2.default.cloneElement(this.props.children, {
217+
marker: this.marker,
217218
google: this.props.google,
218-
map: this.props.map })) : null
219+
map: this.props.map
220+
})) : null
219221
);
220222
}
221223
}]);
@@ -233,7 +235,7 @@
233235
});
234236

235237
Marker.defaultProps = {
236-
name: 'Marker'
238+
name: "Marker"
237239
};
238240

239241
exports.default = Marker;

0 commit comments

Comments
 (0)