Last active
June 4, 2016 04:48
-
-
Save nijikokun/ccb84cc11b8c1308d551 to your computer and use it in GitHub Desktop.
Mithril Templates / Helpers
This file contains 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
// 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 | |
} | |
} |
This file contains 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
function map (object, fn) { | |
var arr = [] | |
Object.keys(object).forEach(function (key) { | |
arr.push(fn.call(this, object[key], key, object)) | |
}) | |
return arr | |
} |
This file contains 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
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