render: make removeNode aware that it is removing children from an object that's brought back from the pool

This commit is contained in:
Pierre-Yves Gérardy 2017-11-22 00:05:34 +01:00 committed by Pierre-Yves Gérardy
parent 98c053e12b
commit 39ff8d7217

View file

@ -164,7 +164,7 @@ module.exports = function($window) {
function updateNodes(parent, old, vnodes, recyclingParent, hooks, nextSibling, ns) {
if (old === vnodes && !recyclingParent || old == null && vnodes == null) return
else if (old == null) createNodes(parent, vnodes, 0, vnodes.length, hooks, nextSibling, ns)
else if (vnodes == null) removeNodes(old, 0, old.length, vnodes)
else if (vnodes == null) removeNodes(old, 0, old.length, vnodes, recyclingParent)
else {
var start = 0, commonLength = Math.min(old.length, vnodes.length), originalOldLength = old.length, hasPool = false, isUnkeyed
for(; start < commonLength; start++) {
@ -182,7 +182,7 @@ module.exports = function($window) {
for (; start < originalOldLength; start++) {
if (old[start] === vnodes[start] && !recyclingParent || old[start] == null && vnodes[start] == null) continue
else if (old[start] == null) createNode(parent, vnodes[start], hooks, ns, getNextSibling(old, start + 1, originalOldLength, nextSibling))
else if (vnodes[start] == null) removeNodes(old, start, start + 1, null)
else if (vnodes[start] == null) removeNodes(old, start, start + 1, vnodes, recyclingParent)
else updateNode(parent, old[start], vnodes[start], hooks, getNextSibling(old, start + 1, originalOldLength, nextSibling), recyclingParent, ns)
}
return
@ -207,7 +207,7 @@ module.exports = function($window) {
oldStart++
} else if (v == null) {
if (isUnkeyed){
removeNodes(old, start, start + 1, vnodes)
removeNodes(old, start, start + 1, vnodes, recyclingParent)
oldStart++
}
start++
@ -262,7 +262,7 @@ module.exports = function($window) {
if (end < start) break
}
createNodes(parent, vnodes, start, end + 1, hooks, nextSibling, ns)
removeNodes(old, oldStart, Math.min(oldEnd + 1, originalOldLength), vnodes)
removeNodes(old, oldStart, Math.min(oldEnd + 1, originalOldLength), vnodes, recyclingParent)
if (hasPool) {
var limit = Math.max(oldStart, originalOldLength)
for (; oldEnd >= limit; oldEnd--) {
@ -296,7 +296,7 @@ module.exports = function($window) {
else updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns)
}
else {
removeNode(old, null)
removeNode(old, null, recycling)
createNode(parent, vnode, hooks, ns, nextSibling)
}
}
@ -368,7 +368,7 @@ module.exports = function($window) {
vnode.domSize = vnode.instance.domSize
}
else if (old.instance != null) {
removeNode(old.instance, null)
removeNode(old.instance, null, recycling)
vnode.dom = undefined
vnode.domSize = 0
}
@ -434,18 +434,19 @@ module.exports = function($window) {
}
//remove
function removeNodes(vnodes, start, end, context) {
function removeNodes(vnodes, start, end, context, recycling) {
for (var i = start; i < end; i++) {
var vnode = vnodes[i]
if (vnode != null) {
if (vnode.skip) vnode.skip = false
else removeNode(vnode, context)
else removeNode(vnode, context, recycling)
}
}
}
function removeNode(vnode, context) {
function removeNode(vnode, context, recycling) {
var expected = 1, called = 0
var original = vnode.state
if (!recycling) {
if (vnode.attrs && typeof vnode.attrs.onbeforeremove === "function") {
var result = callHook.call(vnode.attrs.onbeforeremove, vnode)
if (result != null && typeof result.then === "function") {
@ -460,11 +461,14 @@ module.exports = function($window) {
result.then(continuation, continuation)
}
}
}
continuation()
function continuation() {
if (++called === expected) {
if (!recycling) {
checkState(vnode, original)
onremove(vnode)
}
if (vnode.dom) {
var count = vnode.domSize || 1
if (count > 1) {