Last active
January 30, 2018 17:34
-
-
Save barneycarroll/22d68148b1a2548428872ddf1170648a to your computer and use it in GitHub Desktop.
Find the path to a given vnode inside another vnode eg pave(document.body.vnodes, vnode)
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
const pave = (container, target, path = []) => ( | |
container === target | |
? | |
path | |
: | |
Array.isArray(container) | |
? | |
container.filter((a, i) => pave(a, target, [...path, i])).pop() | |
: | |
container.instance | |
? | |
pave(container.instance, target, [...path, 'instance']) | |
: | |
container.children | |
? | |
pave(container.children, target, [...path, 'children']) | |
: | |
false | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment