From 033cb8780cbc155c7e7e4c402855fcc550ba714e Mon Sep 17 00:00:00 2001 From: Sankho Mallik Date: Mon, 25 Jul 2016 12:36:11 -0400 Subject: [PATCH] adds a list of props and checks against this to see if the map should clear or not --- src/datamap.jsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/datamap.jsx b/src/datamap.jsx index a71b2f3..ccf755b 100644 --- a/src/datamap.jsx +++ b/src/datamap.jsx @@ -1,6 +1,10 @@ import React from 'react'; import Datamaps from 'datamaps'; +const MAP_CLEARING_PROPS = [ + 'setProjection', 'scope', 'height', 'width' +] + export default class Datamap extends React.Component { static propTypes = { @@ -22,10 +26,7 @@ export default class Datamap extends React.Component { } componentWillReceiveProps(newProps) { - if ( - this.props.height !== newProps.height - || this.props.width !== newProps.width - ) { + if (this.propChangeRequiresMapClear(newProps, this.props)) { this.clear(); } } @@ -38,6 +39,10 @@ export default class Datamap extends React.Component { this.clear(); } + propChangeRequiresMapClear(newProps, oldProps) { + return Object.keys(newProps).filter((prop) => MAP_CLEARING_PROPS.indexOf(prop) !== -1).filter((prop) => oldProps[prop] !== newProps[prop]).length > 0 + } + clear() { const { container } = this.refs;