render: make removeNode aware that it is removing children from an object that's brought back from the pool
This commit is contained in:
parent
98c053e12b
commit
39ff8d7217
1 changed files with 26 additions and 22 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue