Last active
May 24, 2016 20:22
-
-
Save JamesKyburz/f0d8536c6ad7f144989984655dadf226 to your computer and use it in GitHub Desktop.
lifecycle
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
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