Skip to content

Instantly share code, notes, and snippets.

@HendrikRoth
Forked from nijikokun/m.component.js
Last active August 29, 2015 14:20
Show Gist options
  • Save HendrikRoth/1ad564ab01e88b61d3e1 to your computer and use it in GitHub Desktop.
Save HendrikRoth/1ad564ab01e88b61d3e1 to your computer and use it in GitHub Desktop.
// 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
}
}
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