@@ -3,9 +3,6 @@ import React, { Component } from 'react';
3
3
import PropTypes from 'prop-types' ;
4
4
import ReactDOM from 'react-dom' ;
5
5
6
- // libs
7
- import shallowEqual from 'fbjs/lib/shallowEqual' ;
8
-
9
6
// helpers
10
7
import GoogleMapMap from './google_map_map' ;
11
8
import MarkerDispatcher from './marker_dispatcher' ;
@@ -22,8 +19,10 @@ import raf from './utils/raf';
22
19
import pick from './utils/pick' ;
23
20
import omit from './utils/omit' ;
24
21
import log2 from './utils/math/log2' ;
22
+ import isEmpty from './utils/isEmpty' ;
25
23
import isNumber from './utils/isNumber' ;
26
24
import detectBrowser from './utils/detect' ;
25
+ import shallowEqual from './utils/shallowEqual' ;
27
26
import isPlainObject from './utils/isPlainObject' ;
28
27
import isArraysEqualEps from './utils/isArraysEqualEps' ;
29
28
import detectElementResize from './utils/detectElementResize' ;
@@ -209,18 +208,13 @@ export default class GoogleMap extends Component {
209
208
) ;
210
209
}
211
210
212
- if (
213
- this . props . center === undefined &&
214
- this . props . defaultCenter === undefined
215
- ) {
211
+ if ( isEmpty ( this . props . center ) && isEmpty ( this . props . defaultCenter ) ) {
216
212
console . warn (
217
213
'GoogleMap: center or defaultCenter property must be defined' // eslint-disable-line no-console
218
214
) ;
219
215
}
220
216
221
- if (
222
- this . props . zoom === undefined && this . props . defaultZoom === undefined
223
- ) {
217
+ if ( isEmpty ( this . props . zoom ) && isEmpty ( this . props . defaultZoom ) ) {
224
218
console . warn (
225
219
'GoogleMap: zoom or defaultZoom property must be defined' // eslint-disable-line no-console
226
220
) ;
@@ -288,17 +282,15 @@ export default class GoogleMap extends Component {
288
282
289
283
componentWillReceiveProps ( nextProps ) {
290
284
if ( process . env . NODE_ENV !== 'production' ) {
291
- if ( this . props . defaultCenter !== nextProps . defaultCenter ) {
285
+ if ( ! shallowEqual ( this . props . defaultCenter , nextProps . defaultCenter ) ) {
292
286
console . warn (
293
- 'GoogleMap: defaultCenter prop changed. ' + // eslint-disable-line
294
- "You can't change default props."
287
+ "GoogleMap: defaultCenter prop changed. You can't change default props."
295
288
) ;
296
289
}
297
290
298
- if ( this . props . defaultZoom !== nextProps . defaultZoom ) {
291
+ if ( ! shallowEqual ( this . props . defaultZoom , nextProps . defaultZoom ) ) {
299
292
console . warn (
300
- 'GoogleMap: defaultZoom prop changed. ' + // eslint-disable-line
301
- "You can't change default props."
293
+ "GoogleMap: defaultZoom prop changed. You can't change default props."
302
294
) ;
303
295
}
304
296
}
@@ -337,26 +329,24 @@ export default class GoogleMap extends Component {
337
329
}
338
330
}
339
331
340
- if ( nextProps . zoom !== undefined ) {
332
+ if ( ! isEmpty ( nextProps . zoom ) ) {
341
333
// if zoom chaged by user
342
334
if ( Math . abs ( nextProps . zoom - this . props . zoom ) > 0 ) {
343
335
this . map_ . setZoom ( nextProps . zoom ) ;
344
336
}
345
337
}
346
338
347
- if (
348
- this . props . draggable !== undefined && nextProps . draggable === undefined
349
- ) {
339
+ if ( ! isEmpty ( this . props . draggable ) && isEmpty ( nextProps . draggable ) ) {
350
340
// reset to default
351
341
this . map_ . setOptions ( { draggable : this . defaultDraggableOption_ } ) ;
352
- } else if ( this . props . draggable !== nextProps . draggable ) {
342
+ } else if ( ! shallowEqual ( this . props . draggable , nextProps . draggable ) ) {
353
343
// also prevent this on window 'mousedown' event to prevent map move
354
344
this . map_ . setOptions ( { draggable : nextProps . draggable } ) ;
355
345
}
356
346
357
347
// use shallowEqual to try avoid calling map._setOptions if only the ref changes
358
348
if (
359
- nextProps . options !== undefined &&
349
+ ! isEmpty ( nextProps . options ) &&
360
350
! shallowEqual ( this . props . options , nextProps . options )
361
351
) {
362
352
const mapPlainObjects = pick ( this . maps_ , isPlainObject ) ;
@@ -374,7 +364,7 @@ export default class GoogleMap extends Component {
374
364
this . map_ . setOptions ( options ) ;
375
365
}
376
366
377
- if ( nextProps . layerTypes !== this . props . layerTypes ) {
367
+ if ( ! shallowEqual ( nextProps . layerTypes , this . props . layerTypes ) ) {
378
368
Object . keys ( this . layers_ ) . forEach ( layerKey => {
379
369
this . layers_ [ layerKey ] . setMap ( null ) ;
380
370
delete this . layers_ [ layerKey ] ;
@@ -395,7 +385,7 @@ export default class GoogleMap extends Component {
395
385
componentDidUpdate ( prevProps ) {
396
386
this . markersDispatcher_ . emit ( 'kON_CHANGE' ) ;
397
387
398
- if ( this . props . hoverDistance !== prevProps . hoverDistance ) {
388
+ if ( ! shallowEqual ( this . props . hoverDistance , prevProps . hoverDistance ) ) {
399
389
this . markersDispatcher_ . emit ( 'kON_MOUSE_POSITION_CHANGE' ) ;
400
390
}
401
391
}
@@ -453,7 +443,7 @@ export default class GoogleMap extends Component {
453
443
} ;
454
444
455
445
_computeMinZoom = minZoom => {
456
- if ( minZoom !== undefined && minZoom !== null ) {
446
+ if ( ! isEmpty ( minZoom ) ) {
457
447
return minZoom ;
458
448
}
459
449
return this . _getMinZoom ( ) ;
@@ -541,7 +531,7 @@ export default class GoogleMap extends Component {
541
531
: this . props . options ;
542
532
const defaultOptions = defaultOptions_ ( mapPlainObjects ) ;
543
533
544
- const draggableOptions = this . props . draggable !== undefined && {
534
+ const draggableOptions = ! isEmpty ( this . props . draggable ) && {
545
535
draggable : this . props . draggable ,
546
536
} ;
547
537
@@ -555,7 +545,7 @@ export default class GoogleMap extends Component {
555
545
...propsOptions ,
556
546
} ;
557
547
558
- this . defaultDraggableOption_ = preMapOptions . draggable !== undefined
548
+ this . defaultDraggableOption_ = ! isEmpty ( preMapOptions . draggable )
559
549
? preMapOptions . draggable
560
550
: this . defaultDraggableOption_ ;
561
551
0 commit comments