Skip to content

Instantly share code, notes, and snippets.

@mnichols
Last active October 2, 2017 19:54
Show Gist options
  • Save mnichols/6e3cc5ca7d9c0f31d101b62ea80f4432 to your computer and use it in GitHub Desktop.
Save mnichols/6e3cc5ca7d9c0f31d101b62ea80f4432 to your computer and use it in GitHub Desktop.
component structure
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