Skip to content

Instantly share code, notes, and snippets.

@nijikokun
Last active June 4, 2016 04:48
Show Gist options
  • Save nijikokun/ccb84cc11b8c1308d551 to your computer and use it in GitHub Desktop.
Save nijikokun/ccb84cc11b8c1308d551 to your computer and use it in GitHub Desktop.
Mithril Templates / Helpers
// var ListComponent = m.component({ ... }) -> component
// var list = ListComponent() -> component instance
// list.view() -> view
m.component = function (component) {
return function (options, content) {
var controller = new component.controller(options)
controller.view = function () {
return component.view(controller, arguments[0] || options, arguments[1] || content)
}
return controller
}
}
function map (object, fn) {
var arr = []
Object.keys(object).forEach(function (key) {
arr.push(fn.call(this, object[key], key, object))
})
return arr
}
var ListComponent = m.component({
controller: function (options) {
var state = {}
return state
},
view: function (state) {
return [
m('div', 'testing')
]
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment