accept component as first argument to m()

This commit is contained in:
Jason Staten 2015-06-01 15:11:44 -06:00
parent 26a6664cd0
commit d89810234a
2 changed files with 18 additions and 1 deletions

View file

@ -34,6 +34,7 @@ var m = (function app(window, undefined) {
*/
function m() {
var args = [].slice.call(arguments);
if (type.call(args[0]) == OBJECT) return parameterize(args[0], args.slice(1));
var hasAttrs = args[1] != null && type.call(args[1]) === OBJECT && !("tag" in args[1] || "view" in args[1]) && !("subtree" in args[1]);
var attrs = hasAttrs ? args[1] : {};
var classAttrName = "class" in attrs ? "class" : "className";

View file

@ -47,7 +47,23 @@ function testMithril(mock) {
var v2 = m(".foo", {class: "bar", onclick: function() {}})
return Object.keys(v1.attrs).join() === Object.keys(v2.attrs).join()
})
test(function() {
//m should proxy object first arg to m.component
var component = {
controller: function(args) {
this.args = args
},
view: function(ctrl) {
return m("div", "testing")
}
}
var args = {age: 12}
var c1 = m(component, args).controller()
var c2 = m.component(component, args).controller()
return c1.args === args && c1.args == c2.args
})
//m.mount
test(function() {
var root = mock.document.createElement("div")