MCPcopy Index your code
hub / github.com/TruthHun/BookStack / updateChildren

Function updateChildren

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

Source from the content-addressed store, hash-verified

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