Browse Source

整理代码

es6
guy 3 years ago
parent
commit
94eaec6ec3
  1. 21
      src/core/wrapper/layout.js

21
src/core/wrapper/layout.js

@ -440,19 +440,19 @@ BI.Layout = BI.inherit(BI.Widget, {
newStartVnode = newCh[++newStartIdx]; newStartVnode = newCh[++newStartIdx];
} else { } else {
var sameOldVnode = findOldVnode(oldCh, newStartVnode, oldStartIdx, oldEndIdx); var sameOldVnode = findOldVnode(oldCh, newStartVnode, oldStartIdx, oldEndIdx);
if (BI.isNull(sameOldVnode)) { // 不存在就把新的放到左边 if (BI.isNull(sameOldVnode[0])) { // 不存在就把新的放到左边
delete self._children[self._getChildName(newStartIdx)]; delete self._children[self._getChildName(newStartIdx)];
var node = addNode(newStartVnode, newStartIdx); var node = addNode(newStartVnode, newStartIdx);
insertBefore(node, oldStartVnode); insertBefore(node, oldStartVnode);
} else { // 如果新节点在旧节点区间中存在就复用一下 } else { // 如果新节点在旧节点区间中存在就复用一下
BI.each(oldCh, function (index, child) { var sameOldIndex = sameOldVnode[1];
if (child && sameVnode(child, newStartVnode)) { updated = self.patchItem(sameOldVnode[0], newStartVnode, sameOldIndex, newStartIdx) || updated;
updated = self.patchItem(sameOldVnode, newStartVnode, index, index) || updated; children[sameOldVnode[0].key == null ? newStartIdx : sameOldVnode[0].key] = self._children[self._getChildName(newStartIdx)] = self._children[self._getChildName(sameOldIndex)];
children[sameOldVnode.key == null ? index : sameOldVnode.key] = self._children[self._getChildName(index)]; if (newStartIdx !== sameOldIndex) {
oldCh[index] = undefined; delete self._children[self._getChildName(sameOldIndex)];
insertBefore(sameOldVnode, oldStartVnode);
} }
}); oldCh[sameOldIndex] = undefined;
insertBefore(sameOldVnode[0], oldStartVnode);
} }
newStartVnode = newCh[++newStartIdx]; newStartVnode = newCh[++newStartIdx];
} }
@ -531,13 +531,14 @@ BI.Layout = BI.inherit(BI.Widget, {
} }
function findOldVnode (vnodes, vNode, beginIdx, endIdx) { function findOldVnode (vnodes, vNode, beginIdx, endIdx) {
var i, found; var i, found, findIndex;
for (i = beginIdx; i <= endIdx; ++i) { for (i = beginIdx; i <= endIdx; ++i) {
if (vnodes[i] && sameVnode(vnodes[i], vNode)) { if (vnodes[i] && sameVnode(vnodes[i], vNode)) {
found = vnodes[i]; found = vnodes[i];
findIndex = i;
} }
} }
return found; return [found, findIndex];
} }
return updated; return updated;

Loading…
Cancel
Save