Last active
October 2, 2018 13:18
-
-
Save zaceno/aef8cb759e44616536d52479b25ba60e to your computer and use it in GitHub Desktop.
HAV2 with subviews
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
const resolve = (node, state) => { | |
if (node == null) { | |
//just return it | |
} else if (Array.isArray(node)) { | |
node = node.map(function (n) { return resolve(n, state)}) | |
node = Array.prototype.concat.apply([], node) | |
node = node.filter(function (n) { return n != null }) | |
} else if (node.name === '$') { | |
node = resolve(node.props.f(state), state) | |
} else if (node.children) { | |
node.children = resolve(node.children, state) | |
} else { | |
node = {name: '' + node, props: {}, children: [], type: 2, element: undefined, key: null} | |
} | |
return node | |
} | |
const view = f => ({name: '$', props: {f}, children: [], type: 0, element: undefined, key: null}) | |
const withViews = app => def => app({ | |
...def, | |
view: state => resolve(view(def.view), state) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment