Skip to content

Instantly share code, notes, and snippets.

@JamesKyburz
Last active May 24, 2016 20:22
Show Gist options
  • Save JamesKyburz/f0d8536c6ad7f144989984655dadf226 to your computer and use it in GitHub Desktop.
Save JamesKyburz/f0d8536c6ad7f144989984655dadf226 to your computer and use it in GitHub Desktop.
lifecycle
function nodes (on, node) {
return [].slice.call(node.childNodes)
.map(nodes.bind(null, on))
.reduce(
function (sum, x) {
return (Array.isArray(x) ? x : [x]).concat(sum)
}, [node]
)
.filter(Boolean)
.forEach((node) => {
if (node[on]) node[on](node)
})
}
store.subscribe(() => yo.update(el, render(), {
onNodeAdded (node) { nodes('onadd', node) },
onNodeDiscarded (node) { nodes('ondiscard', node) }
}))
nodes('onadd', el)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment