Skip to content

Instantly share code, notes, and snippets.

@developit
Last active March 21, 2017 14:05
Show Gist options
  • Select an option

  • Save developit/8b31e8144d06bf30a780aa1216722acb to your computer and use it in GitHub Desktop.

Select an option

Save developit/8b31e8144d06bf30a780aa1216722acb to your computer and use it in GitHub Desktop.
Recursively invoke forceUpdate() on a tree of components. Demo: https://jsfiddle.net/developit/642ctu04/
/** Invoke `.forceUpdate()` on a component and all descendants. */
export default function deepForceUpdate(component) {
component.forceUpdate();
// high-order child recursion
if (component._component) {
deepForceUpdate(component._component);
}
else if (component.base) {
updateComponentsFromDom(component.base);
}
}
function updateComponentsFromDom(node, fn) {
let children = node.childNodes;
for (let i=children && children.length; i--; ) {
let child = children[i];
if (child._component) {
deepForceUpdate(child._component);
}
else {
updateComponentsFromDom(child, fn);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment