fix recycling when tag is different in unkeyed node
This commit is contained in:
parent
c196b8b475
commit
7227cc546f
3 changed files with 33 additions and 5 deletions
|
|
@ -341,6 +341,7 @@ var renderService = function($window) {
|
||||||
else {
|
else {
|
||||||
var recycling = isRecyclable(old, vnodes)
|
var recycling = isRecyclable(old, vnodes)
|
||||||
if (recycling) old = old.concat(old.pool)
|
if (recycling) old = old.concat(old.pool)
|
||||||
|
|
||||||
var oldStart = 0, start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map
|
var oldStart = 0, start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map
|
||||||
while (oldEnd >= oldStart && end >= start) {
|
while (oldEnd >= oldStart && end >= start) {
|
||||||
var o = old[oldStart], v = vnodes[start]
|
var o = old[oldStart], v = vnodes[start]
|
||||||
|
|
@ -348,7 +349,7 @@ var renderService = function($window) {
|
||||||
else if (o != null && v != null && o.key === v.key) {
|
else if (o != null && v != null && o.key === v.key) {
|
||||||
oldStart++, start++
|
oldStart++, start++
|
||||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), recycling, ns)
|
updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), recycling, ns)
|
||||||
if (recycling) insertNode(parent, toFragment(o), nextSibling)
|
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var o = old[oldEnd]
|
var o = old[oldEnd]
|
||||||
|
|
@ -366,7 +367,7 @@ var renderService = function($window) {
|
||||||
if (o === v) oldEnd--, end--
|
if (o === v) oldEnd--, end--
|
||||||
else if (o != null && v != null && o.key === v.key) {
|
else if (o != null && v != null && o.key === v.key) {
|
||||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
|
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
|
||||||
if (recycling) insertNode(parent, toFragment(o), nextSibling)
|
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
|
||||||
nextSibling = o.dom
|
nextSibling = o.dom
|
||||||
oldEnd--, end--
|
oldEnd--, end--
|
||||||
}
|
}
|
||||||
|
|
@ -1065,6 +1066,7 @@ m.route = function($window, renderer, pubsub) {
|
||||||
route.prefix = router.setPrefix
|
route.prefix = router.setPrefix
|
||||||
route.set = router.setPath
|
route.set = router.setPath
|
||||||
route.get = router.getPath
|
route.get = router.getPath
|
||||||
|
|
||||||
return route
|
return route
|
||||||
}(window, renderService, redrawService)
|
}(window, renderService, redrawService)
|
||||||
m.mount = function(renderer, pubsub) {
|
m.mount = function(renderer, pubsub) {
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ module.exports = function($window) {
|
||||||
else if (o != null && v != null && o.key === v.key) {
|
else if (o != null && v != null && o.key === v.key) {
|
||||||
oldStart++, start++
|
oldStart++, start++
|
||||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), recycling, ns)
|
updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), recycling, ns)
|
||||||
if (recycling) insertNode(parent, toFragment(o), nextSibling)
|
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var o = old[oldEnd]
|
var o = old[oldEnd]
|
||||||
|
|
@ -138,7 +138,7 @@ module.exports = function($window) {
|
||||||
if (o === v) oldEnd--, end--
|
if (o === v) oldEnd--, end--
|
||||||
else if (o != null && v != null && o.key === v.key) {
|
else if (o != null && v != null && o.key === v.key) {
|
||||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
|
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
|
||||||
if (recycling) insertNode(parent, toFragment(o), nextSibling)
|
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
|
||||||
nextSibling = o.dom
|
nextSibling = o.dom
|
||||||
oldEnd--, end--
|
oldEnd--, end--
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -787,4 +787,30 @@ o.spec("updateNodes", function() {
|
||||||
o(vnodes[0].dom.firstChild).equals(updated[0].dom.firstChild)
|
o(vnodes[0].dom.firstChild).equals(updated[0].dom.firstChild)
|
||||||
o(updated[0].dom.firstChild.nodeName).equals("A")
|
o(updated[0].dom.firstChild.nodeName).equals("A")
|
||||||
})
|
})
|
||||||
|
o("mixed unkeyed tags are not broken by recycle", function() {
|
||||||
|
var vnodes = [{tag: "a"}, {tag: "b"}]
|
||||||
|
var temp = [{tag: "b"}]
|
||||||
|
var updated = [{tag: "a"}, {tag: "b"}]
|
||||||
|
|
||||||
|
render(root, vnodes)
|
||||||
|
render(root, temp)
|
||||||
|
render(root, updated)
|
||||||
|
|
||||||
|
o(root.childNodes.length).equals(2)
|
||||||
|
o(root.childNodes[0].nodeName).equals("A")
|
||||||
|
o(root.childNodes[1].nodeName).equals("B")
|
||||||
|
})
|
||||||
|
o("mixed unkeyed vnode types are not broken by recycle", function() {
|
||||||
|
var vnodes = [{tag: "[", children: [{tag: "a"}]}, {tag: "b"}]
|
||||||
|
var temp = [{tag: "b"}]
|
||||||
|
var updated = [{tag: "[", children: [{tag: "a"}]}, {tag: "b"}]
|
||||||
|
|
||||||
|
render(root, vnodes)
|
||||||
|
render(root, temp)
|
||||||
|
render(root, updated)
|
||||||
|
|
||||||
|
o(root.childNodes.length).equals(2)
|
||||||
|
o(root.childNodes[0].nodeName).equals("A")
|
||||||
|
o(root.childNodes[1].nodeName).equals("B")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue