accept component as first argument to m()
This commit is contained in:
parent
26a6664cd0
commit
d89810234a
2 changed files with 18 additions and 1 deletions
|
|
@ -34,6 +34,7 @@ var m = (function app(window, undefined) {
|
||||||
*/
|
*/
|
||||||
function m() {
|
function m() {
|
||||||
var args = [].slice.call(arguments);
|
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 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 attrs = hasAttrs ? args[1] : {};
|
||||||
var classAttrName = "class" in attrs ? "class" : "className";
|
var classAttrName = "class" in attrs ? "class" : "className";
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,23 @@ function testMithril(mock) {
|
||||||
var v2 = m(".foo", {class: "bar", onclick: function() {}})
|
var v2 = m(".foo", {class: "bar", onclick: function() {}})
|
||||||
return Object.keys(v1.attrs).join() === Object.keys(v2.attrs).join()
|
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
|
//m.mount
|
||||||
test(function() {
|
test(function() {
|
||||||
var root = mock.document.createElement("div")
|
var root = mock.document.createElement("div")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue