render: extract pool addtition logic, don't run onremove on nodes that move from pool to pool (fix #1990)

This commit is contained in:
Pierre-Yves Gérardy 2017-11-02 15:51:06 +01:00 committed by Pierre-Yves Gérardy
parent 7179692fc4
commit 8950760e85
2 changed files with 95 additions and 6 deletions

View file

@ -185,7 +185,7 @@ module.exports = function($window) {
}
}
recycling = recycling || isRecyclable(old, vnodes)
if (recycling) {
if (recycling && old.pool != null) {
var pool = old.pool
old = old.concat(old.pool)
}
@ -250,7 +250,14 @@ module.exports = function($window) {
if (end < start) break
}
createNodes(parent, vnodes, start, end + 1, hooks, nextSibling, ns)
removeNodes(old, oldStart, oldEnd + 1, vnodes)
removeNodes(old, oldStart, Math.min(oldEnd + 1, pool == null ? old.length : old.length - pool.length), vnodes)
if (pool != null) {
var limit = Math.max(oldStart, old.length - pool.length)
for (; oldEnd >= limit; oldEnd--) {
if (old[oldEnd].skip) old[oldEnd].skip = false
else addToPool(old[oldEnd], vnodes)
}
}
}
}
function updateNode(parent, old, vnode, hooks, nextSibling, recycling, ns) {
@ -455,10 +462,7 @@ module.exports = function($window) {
}
}
removeNodeFromDOM(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)
}
addToPool(vnode, context)
}
}
}
@ -467,6 +471,12 @@ module.exports = function($window) {
var parent = node.parentNode
if (parent != null) parent.removeChild(node)
}
function addToPool(vnode, context) {
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) {
if (vnode.attrs && typeof vnode.attrs.onremove === "function") callHook.call(vnode.attrs.onremove, vnode)
if (typeof vnode.tag !== "string") {