Last active
March 21, 2017 14:05
-
-
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/
This file contains hidden or 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
| /** 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