Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created February 17, 2017 18:05
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/0d8de4c998be2f7b56ac130899bfef2f to your computer and use it in GitHub Desktop.
Save barneycarroll/0d8de4c998be2f7b56ac130899bfef2f to your computer and use it in GitHub Desktop.
Mithril v/dom alignment
export default function * vTreeWalker(vnode){
yield vnode
if(vnode.instance)
yield * vTreeWalker(vnode.instance)
else if(Array.isArray(vnode.children))
for(const child in vnode.children)
yield * vTreeWalker(child)
}
@barneycarroll
Copy link
Author

TODO:

  • Patch upstream to nearest dom.vnode for m.render integration (consider fragments - is it possible?)

API:

function malign(dom, vnode, {cycle = 0, post = false, push = true}){
  // dom is the live DOM tree, vnode is the vDOM tree to align to it
  // cycle 0 means run no lifecycle methods - treat vnode tree as static
  // cycle 1 means run oninit and view
  // cycle 2 means run onbeforeupdate and view
  // post means run oncreate if cycle is 1, onupdate if cycle is 2
  // push means to find the upstream mountpoint and merge the aligned vnode into its records

  // returns the mutated vnode
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment