Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Last active January 30, 2018 17:34
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 barneycarroll/22d68148b1a2548428872ddf1170648a to your computer and use it in GitHub Desktop.
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)
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