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