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

Function updateChildren

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

Source from the content-addressed store, hash-verified

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