#466 allow modules as second parameter of m
This commit is contained in:
parent
971b0def51
commit
c81294bce8
2 changed files with 40 additions and 3 deletions
|
|
@ -33,7 +33,7 @@ var m = (function app(window, undefined) {
|
||||||
*/
|
*/
|
||||||
function m() {
|
function m() {
|
||||||
var args = [].slice.call(arguments);
|
var args = [].slice.call(arguments);
|
||||||
var hasAttrs = args[1] != null && type.call(args[1]) === OBJECT && !("tag" 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";
|
||||||
var cell = {tag: "div", attrs: {}};
|
var cell = {tag: "div", attrs: {}};
|
||||||
|
|
@ -232,7 +232,7 @@ var m = (function app(window, undefined) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (data != null && dataType === OBJECT) {
|
else if (data != null && dataType === OBJECT) {
|
||||||
if (data.controller) {
|
if (data.view) {
|
||||||
var module = data
|
var module = data
|
||||||
var controller = cached.controller || new (module.controller || function() {})
|
var controller = cached.controller || new (module.controller || function() {})
|
||||||
if (controller.onunload) unloaders.push({controller: controller, handler: controller.onunload})
|
if (controller.onunload) unloaders.push({controller: controller, handler: controller.onunload})
|
||||||
|
|
|
||||||
|
|
@ -424,6 +424,43 @@ function testMithril(mock) {
|
||||||
|
|
||||||
return loaded === false
|
return loaded === false
|
||||||
})
|
})
|
||||||
|
test(function() {
|
||||||
|
// nested modules under keyed components should render
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
||||||
|
var root = mock.document.createElement("div")
|
||||||
|
var count = 0
|
||||||
|
var App = {
|
||||||
|
controller: function() {},
|
||||||
|
view: function(ctrl) {
|
||||||
|
return m('.outer', [
|
||||||
|
m('.inner', m.module(CommentList, { list: [1, 2, 3] }))
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var CommentList = {
|
||||||
|
controller: function() {},
|
||||||
|
view: function(ctrl, props) {
|
||||||
|
return m('.list', props.list.map(function(i) {
|
||||||
|
return m('.comment', [
|
||||||
|
m.module(Reply, {key: i})
|
||||||
|
])
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var Reply = {
|
||||||
|
controller: function() {},
|
||||||
|
view: function() {
|
||||||
|
count++
|
||||||
|
return m(".reply")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.module(root, App)
|
||||||
|
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
||||||
|
return count === 3
|
||||||
|
})
|
||||||
|
|
||||||
//m.withAttr
|
//m.withAttr
|
||||||
test(function() {
|
test(function() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue