Created
January 6, 2016 17:30
-
-
Save engineersamuel/27ba0e898d263708fb8d to your computer and use it in GitHub Desktop.
componentDidUpdate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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