Skip to content

Instantly share code, notes, and snippets.

@vdsabev
Last active August 17, 2017 10:28
Show Gist options
  • Save vdsabev/b97e25248608bdc1158f41bd33105776 to your computer and use it in GitHub Desktop.
Save vdsabev/b97e25248608bdc1158f41bd33105776 to your computer and use it in GitHub Desktop.
Exploring Unidirectional Components in Mithril
const component = (options = {}) => (vnode) {
let state = { ...options.state, ...vnode.attrs };
const proxyActions = {};
Object.keys(options.actions).forEach((key) => {
proxyActions[key] = (...args) => {
const newState = options.actions[key](state, proxyActions, ...args);
if (newState) {
state = { ...state, ...newState };
}
return state;
};
});
return {
...options.events,
view: () => options.view(vnode, state, proxyActions)
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment