Last active
October 2, 2017 19:54
-
-
Save mnichols/6e3cc5ca7d9c0f31d101b62ea80f4432 to your computer and use it in GitHub Desktop.
component structure
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
import m from 'mithril' | |
import { curry } from 'ramda' | |
const createActions = ({ update }) => { | |
return { | |
someBehavior ({ id }) { | |
update(m => { m.someId = id }) | |
} | |
} | |
} | |
const createHandlers = curry({ actions }, scope) => { | |
const { id } = scope | |
return { | |
onclick (e) { | |
return actions.someBehavior({ id }) | |
} | |
} | |
}) | |
const createView = ({ components, handlers }) => { | |
return { | |
view (vnode) { | |
const { id } = vnode.attrs | |
const { onclick } = handlers(id) | |
return m('button', { | |
type: 'button', | |
onclick | |
}, m(components.otherComponent)) | |
} | |
} | |
} | |
const transform = ({ model }) => { | |
return { whatever } | |
} | |
function createComponent ({ update }) { | |
const actions = createActions({ update }) | |
const handlers = curry(createHandlers({ actions }) | |
const view = createView({ handlers }) | |
return { | |
actions, | |
view, | |
transform | |
} | |
} | |
export default createComponent | |
// OR // | |
export { createComponent, createActions, createHandlers, createView } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment