|
|
@ -421,9 +421,22 @@ BI.Layout = BI.inherit(BI.Widget, { |
|
|
|
oldEndVnode = oldCh[--oldEndIdx]; |
|
|
|
oldEndVnode = oldCh[--oldEndIdx]; |
|
|
|
newStartVnode = newCh[++newStartIdx]; |
|
|
|
newStartVnode = newCh[++newStartIdx]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
var node = addNode(newStartVnode); |
|
|
|
var sameOldVnode = findOldVnode(oldCh, newStartVnode, oldStartIdx, oldEndIdx); |
|
|
|
insertBefore(node, oldStartVnode); |
|
|
|
if (BI.isNull(sameOldVnode)) { // 不存在就把新的放到左边
|
|
|
|
newStartVnode = newCh[++newStartIdx]; |
|
|
|
var node = addNode(newStartVnode); |
|
|
|
|
|
|
|
insertBefore(node, oldStartVnode); |
|
|
|
|
|
|
|
newStartVnode = newCh[++newStartIdx]; |
|
|
|
|
|
|
|
} else { // 如果新节点在就旧节点区间中存在就复用一下
|
|
|
|
|
|
|
|
BI.each(oldCh, function (index, child) { |
|
|
|
|
|
|
|
if (child && sameVnode(child, newStartVnode)) { |
|
|
|
|
|
|
|
updated = self.patchItem(sameOldVnode, newStartVnode, index) || updated; |
|
|
|
|
|
|
|
children[sameOldVnode.key == null ? self._getChildName(index) : sameOldVnode.key] = self._children[self._getChildName(index)]; |
|
|
|
|
|
|
|
oldCh[index] = undefined; |
|
|
|
|
|
|
|
insertBefore(sameOldVnode, oldStartVnode); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
newStartVnode = newCh[++newStartIdx]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (oldStartIdx > oldEndIdx) { |
|
|
|
if (oldStartIdx > oldEndIdx) { |
|
|
@ -467,9 +480,13 @@ BI.Layout = BI.inherit(BI.Widget, { |
|
|
|
|
|
|
|
|
|
|
|
function removeVnodes (vnodes, startIdx, endIdx) { |
|
|
|
function removeVnodes (vnodes, startIdx, endIdx) { |
|
|
|
for (; startIdx <= endIdx; ++startIdx) { |
|
|
|
for (; startIdx <= endIdx; ++startIdx) { |
|
|
|
var node = self._getOptions(vnodes[startIdx]); |
|
|
|
var ch = vnodes[startIdx]; |
|
|
|
var key = node.key == null ? self._getChildName(startIdx) : node.key; |
|
|
|
if (BI.isNotNull(ch)) { |
|
|
|
children[key]._destroy(); |
|
|
|
var node = self._getOptions(ch); |
|
|
|
|
|
|
|
var key = node.key == null ? self._getChildName(startIdx) : node.key; |
|
|
|
|
|
|
|
delete self._children[self._getChildName(key)]; |
|
|
|
|
|
|
|
children[key]._destroy(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -495,6 +512,16 @@ BI.Layout = BI.inherit(BI.Widget, { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function findOldVnode (vnodes, vNode, beginIdx, endIdx) { |
|
|
|
|
|
|
|
var i, found; |
|
|
|
|
|
|
|
for (i = beginIdx; i <= endIdx; ++i) { |
|
|
|
|
|
|
|
if (vnodes[i] && sameVnode(vnodes[i], vNode)) { |
|
|
|
|
|
|
|
found = vnodes[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return found; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return updated; |
|
|
|
return updated; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|