Make onbeforeremove done() handlers more robust.
This commit is contained in:
parent
0ddad54e88
commit
0b5800d09a
1 changed files with 37 additions and 30 deletions
|
|
@ -203,7 +203,7 @@ module.exports = function($window) {
|
||||||
else updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns)
|
else updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
removeNode(parent, old, null, false)
|
removeNode(parent, old, null)
|
||||||
insertNode(parent, createNode(vnode, hooks, undefined), nextSibling)
|
insertNode(parent, createNode(vnode, hooks, undefined), nextSibling)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -265,7 +265,7 @@ module.exports = function($window) {
|
||||||
vnode.domSize = vnode.instance.domSize
|
vnode.domSize = vnode.instance.domSize
|
||||||
}
|
}
|
||||||
else if (old.instance != null) {
|
else if (old.instance != null) {
|
||||||
removeNode(parent, old.instance, null, false)
|
removeNode(parent, old.instance, null)
|
||||||
vnode.dom = undefined
|
vnode.dom = undefined
|
||||||
vnode.domSize = 0
|
vnode.domSize = 0
|
||||||
}
|
}
|
||||||
|
|
@ -327,41 +327,48 @@ module.exports = function($window) {
|
||||||
var vnode = vnodes[i]
|
var vnode = vnodes[i]
|
||||||
if (vnode != null) {
|
if (vnode != null) {
|
||||||
if (vnode.skip) vnode.skip = false
|
if (vnode.skip) vnode.skip = false
|
||||||
else removeNode(parent, vnode, context, false)
|
else removeNode(parent, vnode, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function removeNode(parent, vnode, context, deferred) {
|
function once(f) {
|
||||||
if (deferred === false) {
|
var called = false
|
||||||
var expected = 0, called = 0
|
return function() {
|
||||||
var callback = function() {
|
if (!called) {
|
||||||
if (++called === expected) removeNode(parent, vnode, context, true)
|
called = true
|
||||||
|
f()
|
||||||
}
|
}
|
||||||
if (vnode.attrs && vnode.attrs.onbeforeremove) {
|
|
||||||
expected++
|
|
||||||
vnode.attrs.onbeforeremove.call(vnode.state, vnode, callback)
|
|
||||||
}
|
|
||||||
if (typeof vnode.tag !== "string" && vnode.tag.onbeforeremove) {
|
|
||||||
expected++
|
|
||||||
vnode.tag.onbeforeremove.call(vnode.state, vnode, callback)
|
|
||||||
}
|
|
||||||
if (expected > 0) return
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
onremove(vnode)
|
function removeNode(parent, vnode, context) {
|
||||||
if (vnode.dom) {
|
var expected = 1, called = 0
|
||||||
var count = vnode.domSize || 1
|
if (vnode.attrs && vnode.attrs.onbeforeremove) {
|
||||||
if (count > 1) {
|
expected++
|
||||||
var dom = vnode.dom
|
vnode.attrs.onbeforeremove.call(vnode.state, vnode, once(continuation))
|
||||||
while (--count) {
|
}
|
||||||
parent.removeChild(dom.nextSibling)
|
if (typeof vnode.tag !== "string" && vnode.tag.onbeforeremove) {
|
||||||
|
expected++
|
||||||
|
vnode.tag.onbeforeremove.call(vnode.state, vnode, once(continuation))
|
||||||
|
}
|
||||||
|
continuation()
|
||||||
|
function continuation() {
|
||||||
|
if (++called === expected) {
|
||||||
|
onremove(vnode)
|
||||||
|
if (vnode.dom) {
|
||||||
|
var count = vnode.domSize || 1
|
||||||
|
if (count > 1) {
|
||||||
|
var dom = vnode.dom
|
||||||
|
while (--count) {
|
||||||
|
parent.removeChild(dom.nextSibling)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (vnode.dom.parentNode != null) parent.removeChild(vnode.dom)
|
||||||
|
if (context != null && vnode.domSize == null && !hasIntegrationMethods(vnode.attrs) && typeof vnode.tag === "string") { //TODO test custom elements
|
||||||
|
if (!context.pool) context.pool = [vnode]
|
||||||
|
else context.pool.push(vnode)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (vnode.dom.parentNode != null) parent.removeChild(vnode.dom)
|
|
||||||
if (context != null && vnode.domSize == null && !hasIntegrationMethods(vnode.attrs) && typeof vnode.tag === "string") { //TODO test custom elements
|
|
||||||
if (!context.pool) context.pool = [vnode]
|
|
||||||
else context.pool.push(vnode)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function onremove(vnode) {
|
function onremove(vnode) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue