#1281 fixed recyling edge case
This commit is contained in:
parent
59e4e8ff26
commit
730c960416
5 changed files with 85 additions and 63 deletions
|
|
@ -132,7 +132,7 @@ module.exports = function($window) {
|
|||
var oldStart = 0, start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map
|
||||
while (oldEnd >= oldStart && end >= start) {
|
||||
var o = old[oldStart], v = vnodes[start]
|
||||
if (o === v) oldStart++, start++
|
||||
if (o === v && !recycling) oldStart++, start++
|
||||
else if (o != null && v != null && o.key === v.key) {
|
||||
oldStart++, start++
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), recycling, ns)
|
||||
|
|
@ -140,10 +140,10 @@ module.exports = function($window) {
|
|||
}
|
||||
else {
|
||||
var o = old[oldEnd]
|
||||
if (o === v) oldEnd--, start++
|
||||
if (o === v && !recycling) oldEnd--, start++
|
||||
else if (o != null && v != null && o.key === v.key) {
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
|
||||
if (start < end) insertNode(parent, toFragment(o), getNextSibling(old, oldStart, nextSibling))
|
||||
if (recycling || start < end) insertNode(parent, toFragment(o), getNextSibling(old, oldStart, nextSibling))
|
||||
oldEnd--, start++
|
||||
}
|
||||
else break
|
||||
|
|
@ -151,7 +151,7 @@ module.exports = function($window) {
|
|||
}
|
||||
while (oldEnd >= oldStart && end >= start) {
|
||||
var o = old[oldEnd], v = vnodes[end]
|
||||
if (o === v) oldEnd--, end--
|
||||
if (o === v && !recycling) oldEnd--, end--
|
||||
else if (o != null && v != null && o.key === v.key) {
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
|
||||
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
|
||||
|
|
|
|||
|
|
@ -148,7 +148,6 @@ o.spec("oninit", function() {
|
|||
render(root, [])
|
||||
render(root, [updated])
|
||||
|
||||
o(vnode.dom).equals(updated.dom)
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
|
|
@ -201,16 +200,4 @@ o.spec("oninit", function() {
|
|||
o(vnode.dom.oninit).equals(undefined)
|
||||
o(vnode.dom.attributes["oninit"]).equals(undefined)
|
||||
})
|
||||
o("calls oninit on recycle", function() {
|
||||
var create = o.spy()
|
||||
var vnodes = [{tag: "div", key: 1, attrs: {oninit: create}}]
|
||||
var temp = []
|
||||
var updated = [{tag: "div", key: 1, attrs: {oninit: create}}]
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
o(create.callCount).equals(2)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -211,4 +211,38 @@ o.spec("updateElement", function() {
|
|||
|
||||
o(updated.dom.attributes["class"].nodeValue).equals("b")
|
||||
})
|
||||
o("restores correctly when recycling", function() {
|
||||
var vnode = {tag: "div", key: 1}
|
||||
var updated = {tag: "div", key: 2}
|
||||
|
||||
render(root, [vnode])
|
||||
var a = vnode.dom
|
||||
|
||||
render(root, [updated])
|
||||
|
||||
render(root, [vnode])
|
||||
var c = vnode.dom
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(a).equals(c)
|
||||
})
|
||||
o("restores correctly when recycling via map", function() {
|
||||
var a = {tag: "div", key: 1}
|
||||
var b = {tag: "div", key: 2}
|
||||
var c = {tag: "div", key: 3}
|
||||
var d = {tag: "div", key: 4}
|
||||
var e = {tag: "div", key: 5}
|
||||
var f = {tag: "div", key: 6}
|
||||
|
||||
render(root, [a, b, c])
|
||||
var x = root.childNodes[1]
|
||||
|
||||
render(root, [d])
|
||||
|
||||
render(root, [e, b, f])
|
||||
var y = root.childNodes[1]
|
||||
|
||||
o(root.childNodes.length).equals(3)
|
||||
o(x).equals(y)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue