fix onremove across components
This commit is contained in:
parent
7a5978df59
commit
519b352c2c
2 changed files with 41 additions and 6 deletions
|
|
@ -354,12 +354,14 @@ module.exports = function($window) {
|
|||
function onremove(vnode) {
|
||||
if (vnode.attrs && vnode.attrs.onremove) vnode.attrs.onremove.call(vnode.state, vnode)
|
||||
if (typeof vnode.tag !== "string" && vnode.tag.onremove) vnode.tag.onremove.call(vnode.state, vnode)
|
||||
|
||||
var children = vnode.children
|
||||
if (children instanceof Array) {
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var child = children[i]
|
||||
if (child != null) onremove(child)
|
||||
if (vnode.instance != null) onremove(vnode.instance)
|
||||
else {
|
||||
var children = vnode.children
|
||||
if (children instanceof Array) {
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var child = children[i]
|
||||
if (child != null) onremove(child)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,6 +79,39 @@ o.spec("onremove", function() {
|
|||
o(remove.this).equals(vnode.state)
|
||||
o(remove.args[0]).equals(vnode)
|
||||
})
|
||||
o("calls onremove on nested component", function() {
|
||||
var spy = o.spy()
|
||||
var comp = {
|
||||
view: function() {return m(outer)}
|
||||
}
|
||||
var outer = {
|
||||
view: function() {return m(inner)}
|
||||
}
|
||||
var inner = {
|
||||
onremove: spy,
|
||||
view: function() {return m("div")}
|
||||
}
|
||||
render(root, {tag: comp})
|
||||
render(root, null)
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
o("calls onremove on nested component child", function() {
|
||||
var spy = o.spy()
|
||||
var comp = {
|
||||
view: function() {return m(outer)}
|
||||
}
|
||||
var outer = {
|
||||
view: function() {return m(inner, m("a", {onremove: spy}))}
|
||||
}
|
||||
var inner = {
|
||||
view: function(vnode) {return m("div", vnode.children)}
|
||||
}
|
||||
render(root, {tag: comp})
|
||||
render(root, null)
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
o("does not set onremove as an event handler", function() {
|
||||
var remove = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onremove: remove}, children: []}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue