Skip to content

Commit

Permalink
adds a list of props and checks against this to see if the map should…
Browse files Browse the repository at this point in the history
… clear or not
  • Loading branch information
Sankho Mallik committed Jul 25, 2016
1 parent cd54a85 commit 05d9e5d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/datamap.jsx
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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.clear();
}
}
Expand All @@ -38,6 +39,10 @@ export default class Datamap extends React.Component {
this.clear();
}

propChangeRequiresMapClear(newProps) {
Object.keys(newProps).filter((prop) => MAP_CLEARING_PROPS.indexOf(prop) !== -1).filter((prop) => this.props[prop] !== newProps[prop]).length > 0
}

clear() {
const { container } = this.refs;

Expand Down

0 comments on commit 05d9e5d

Please sign in to comment.