Skip to content

Commit

Permalink
simplify matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed May 20, 2023
1 parent 1a4dd2f commit c0e74c7
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/diff/children.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,43 +320,33 @@ function findMatchingIndex(
skewedIndex,
remainingOldChildren
) {
const key = childVNode.key;
const type = childVNode.type;
let x = skewedIndex - 1;
let y = skewedIndex + 1;
let oldVNode = oldChildren[skewedIndex];

if (
oldVNode === null ||
(oldVNode &&
childVNode.key == oldVNode.key &&
childVNode.type === oldVNode.type)
(oldVNode && key == oldVNode.key && type === oldVNode.type)
) {
return skewedIndex;
} else if (remainingOldChildren > (oldVNode != null ? 1 : 0)) {
// eslint-disable-next-line no-constant-condition
while (true) {
while (x >= 0 || y < oldChildren.length) {
if (x >= 0) {
oldVNode = oldChildren[x];
if (
oldVNode &&
childVNode.key == oldVNode.key &&
childVNode.type === oldVNode.type
) {
if (oldVNode && key == oldVNode.key && type === oldVNode.type) {
return x;
}
x--;
}

if (y < oldChildren.length) {
oldVNode = oldChildren[y];
if (
oldVNode &&
childVNode.key == oldVNode.key &&
childVNode.type === oldVNode.type
) {
if (oldVNode && key == oldVNode.key && type === oldVNode.type) {
return y;
}
y++;
} else if (x < 0) {
return -1;
}
}
}
Expand Down

0 comments on commit c0e74c7

Please sign in to comment.