From e44daa7708c565e8cea70889c286106748d4e6ab Mon Sep 17 00:00:00 2001 From: "wangzhangsheng(cary)" Date: Fri, 10 Dec 2021 15:18:00 +0800 Subject: [PATCH] chore(refactor): make patching child vnode more readable --- src/init.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/init.ts b/src/init.ts index 4500eba..5f09803 100644 --- a/src/init.ts +++ b/src/init.ts @@ -308,20 +308,20 @@ export function init(modules: Array>, domApi?: DOMAPI) { newStartVnode = newCh[++newStartIdx]; } } - if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) { - if (oldStartIdx > oldEndIdx) { - before = newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].elm; - addVnodes( - parentElm, - before, - newCh, - newStartIdx, - newEndIdx, - insertedVnodeQueue - ); - } else { - removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx); - } + + if (newStartIdx <= newEndIdx) { + before = newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].elm; + addVnodes( + parentElm, + before, + newCh, + newStartIdx, + newEndIdx, + insertedVnodeQueue + ); + } + if (oldStartIdx <= oldEndIdx) { + removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx); } }