Skip to content

Instantly share code, notes, and snippets.

@zaceno
Last active October 2, 2018 13:18
Show Gist options
  • Save zaceno/aef8cb759e44616536d52479b25ba60e to your computer and use it in GitHub Desktop.
Save zaceno/aef8cb759e44616536d52479b25ba60e to your computer and use it in GitHub Desktop.
HAV2 with subviews
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