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

Function updateChildren

static/vuejs/vue.esm.js:4829–4902  ·  view source on GitHub ↗
(parentElm, oldCh, newCh, insertedVnodeQueue, removeOnly)

Source from the content-addressed store, hash-verified

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