MCPcopy Create free account
hub / github.com/TruthHun/BookStack / updateChildren

Function updateChildren

static/vuejs/vue.common.js:4831–4904  ·  view source on GitHub ↗
(parentElm, oldCh, newCh, insertedVnodeQueue, removeOnly)

Source from the content-addressed store, hash-verified

4829 }
4830
4831 function updateChildren (parentElm, oldCh, newCh, insertedVnodeQueue, removeOnly) {
4832 var oldStartIdx = 0;
4833 var newStartIdx = 0;
4834 var oldEndIdx = oldCh.length - 1;
4835 var oldStartVnode = oldCh[0];
4836 var oldEndVnode = oldCh[oldEndIdx];
4837 var newEndIdx = newCh.length - 1;
4838 var newStartVnode = newCh[0];
4839 var newEndVnode = newCh[newEndIdx];
4840 var oldKeyToIdx, idxInOld, elmToMove, refElm;
4841
4842 // removeOnly is a special flag used only by <transition-group>
4843 // to ensure removed elements stay in correct relative positions
4844 // during leaving transitions
4845 var canMove = !removeOnly;
4846
4847 while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
4848 if (isUndef(oldStartVnode)) {
4849 oldStartVnode = oldCh[++oldStartIdx]; // Vnode has been moved left
4850 } else if (isUndef(oldEndVnode)) {
4851 oldEndVnode = oldCh[--oldEndIdx];
4852 } else if (sameVnode(oldStartVnode, newStartVnode)) {
4853 patchVnode(oldStartVnode, newStartVnode, insertedVnodeQueue);
4854 oldStartVnode = oldCh[++oldStartIdx];
4855 newStartVnode = newCh[++newStartIdx];
4856 } else if (sameVnode(oldEndVnode, newEndVnode)) {
4857 patchVnode(oldEndVnode, newEndVnode, insertedVnodeQueue);
4858 oldEndVnode = oldCh[--oldEndIdx];
4859 newEndVnode = newCh[--newEndIdx];
4860 } else if (sameVnode(oldStartVnode, newEndVnode)) { // Vnode moved right
4861 patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue);
4862 canMove && nodeOps.insertBefore(parentElm, oldStartVnode.elm, nodeOps.nextSibling(oldEndVnode.elm));
4863 oldStartVnode = oldCh[++oldStartIdx];
4864 newEndVnode = newCh[--newEndIdx];
4865 } else if (sameVnode(oldEndVnode, newStartVnode)) { // Vnode moved left
4866 patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue);
4867 canMove && nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
4868 oldEndVnode = oldCh[--oldEndIdx];
4869 newStartVnode = newCh[++newStartIdx];
4870 } else {
4871 if (isUndef(oldKeyToIdx)) { oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx); }
4872 idxInOld = isDef(newStartVnode.key) ? oldKeyToIdx[newStartVnode.key] : null;
4873 if (isUndef(idxInOld)) { // New element
4874 createElm(newStartVnode, insertedVnodeQueue, parentElm, oldStartVnode.elm);
4875 newStartVnode = newCh[++newStartIdx];
4876 } else {
4877 elmToMove = oldCh[idxInOld];
4878 /* istanbul ignore if */
4879 if (process.env.NODE_ENV !== 'production' && !elmToMove) {
4880 warn(
4881 'It seems there are duplicate keys that is causing an update error. ' +
4882 'Make sure each v-for item has a unique key.'
4883 );
4884 }
4885 if (sameVnode(elmToMove, newStartVnode)) {
4886 patchVnode(elmToMove, newStartVnode, insertedVnodeQueue);
4887 oldCh[idxInOld] = undefined;
4888 canMove && nodeOps.insertBefore(parentElm, newStartVnode.elm, oldStartVnode.elm);

Callers 1

patchVnodeFunction · 0.70

Calls 9

isUndefFunction · 0.70
sameVnodeFunction · 0.70
patchVnodeFunction · 0.70
createKeyToOldIdxFunction · 0.70
isDefFunction · 0.70
createElmFunction · 0.70
addVnodesFunction · 0.70
removeVnodesFunction · 0.70
warnFunction · 0.50

Tested by

no test coverage detected