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

Function updateChildren

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

Source from the content-addressed store, hash-verified

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