Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@engineersamuel
Created January 6, 2016 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save engineersamuel/27ba0e898d263708fb8d to your computer and use it in GitHub Desktop.
Save engineersamuel/27ba0e898d263708fb8d to your computer and use it in GitHub Desktop.
componentDidUpdate
componentDidUpdate(prevProps) {
// The list of keys seen in the previous render
let currentKeys = _.map(prevProps.children, (n) => n.key);
// The latest list of keys that have been rendered
let newKeys = _.map(this.props.children, (n) => n.key);
// Find which keys are new between the current set of keys and any new children passed to this component
let addKeys = _.difference(newKeys, currentKeys);
// Find which keys have been removed between the current set of keys and any new children passed to this component
let removeKeys = _.difference(currentKeys, newKeys);
if (removeKeys.length > 0) {
_.each(removeKeys, removeKey => this.iso.remove(document.getElementById(removeKey)));
this.iso.arrange();
}
if (addKeys.length > 0) {
this.iso.addItems(_.map(addKeys, (addKey) => document.getElementById(addKey)));
this.iso.arrange();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment