Skip to content

Commit

Permalink
simplify more checks
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed May 18, 2023
1 parent d58f60e commit 63e70fd
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/diff/children.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,11 @@ export function diffChildren(
if (matchingIndex === -1) {
oldVNode = EMPTY_OBJ;
} else {
oldVNode = oldChildren[matchingIndex];
oldVNode = oldChildren[matchingIndex] || EMPTY_OBJ;
oldChildren[matchingIndex] = undefined;
remainingOldChildren--;
}

oldVNode = oldVNode || EMPTY_OBJ;
let isMounting =
isHydrating || oldVNode === EMPTY_OBJ || oldVNode._original === null;

// Morph the old element into the new one, but don't append it to the dom yet
diff(
parentDom,
Expand All @@ -157,12 +153,13 @@ export function diffChildren(
firstChildDom = newDom;
}

let isMounting = oldVNode === EMPTY_OBJ || oldVNode._original === null;
let hasMatchingIndex = !isMounting && matchingIndex === skewedIndex;
if (isMounting) {
if (matchingIndex == -1) {
skew--;
}
} else if (!hasMatchingIndex) {
} else if (matchingIndex !== skewedIndex) {
if (matchingIndex === skewedIndex + 1) {
skew++;
hasMatchingIndex = true;
Expand All @@ -186,11 +183,11 @@ export function diffChildren(
}

skewedIndex = i + skew;
if (matchingIndex == i && !isMounting) {
hasMatchingIndex = true;
}
hasMatchingIndex =
hasMatchingIndex || (matchingIndex == i && !isMounting);

if (
!isHydrating &&
!isMounting &&
typeof childVNode.type == 'function' &&
(matchingIndex !== skewedIndex ||
Expand Down

0 comments on commit 63e70fd

Please sign in to comment.