Skip to content

Commit c739eae

Browse files
committed
easier to read
1 parent c189ade commit c739eae

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

src/diff/children.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,8 @@ function constructNewChildrenArray(newParentVNode, renderResult, oldChildren) {
320320
skew--;
321321
}
322322
} else if (matchingIndex < skewedIndex) {
323-
// Our matched DOM-node is further in the negative way in the list of children
324-
// than where it's at now.
325-
326-
// When the remaining old chiildren is less than the new children
327-
// plus our skewed index we know we are dealing with a growing list
328-
if (remainingOldChildren < newChildrenLength + skewedIndex) {
329-
skew += matchingIndex + skewedIndex;
330-
} else {
331-
skew = 0;
332-
}
323+
// When our new position is in front of our old position than we increase the skew
324+
skew++;
333325
}
334326

335327
// Move this VNode's DOM if the original index (matchingIndex) doesn't

test/browser/render.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,9 @@ describe('render()', () => {
16361636
);
16371637
const a = ['0', '1', '2', '3', '4', '5', '6'];
16381638
const b = ['1', '3', '5', '2', '6', '4', '0'];
1639+
const c = ['11', '3', '1', '4', '6', '2', '5', '0', '9', '10'];
16391640
render(<App items={a} />, scratch);
1641+
clearLog();
16401642
expect(scratch.innerHTML).to.equal(
16411643
`<div>${a.map(n => `<div>${n}</div>`).join('')}</div>`
16421644
);
@@ -1645,10 +1647,46 @@ describe('render()', () => {
16451647
expect(scratch.innerHTML).to.equal(
16461648
`<div>${b.map(n => `<div>${n}</div>`).join('')}</div>`
16471649
);
1650+
expect(getLog()).to.deep.equal([
1651+
'<div>0123456.insertBefore(<div>2, <div>6)',
1652+
'<div>0134526.appendChild(<div>4)',
1653+
'<div>0135264.appendChild(<div>0)'
1654+
]);
1655+
clearLog();
1656+
1657+
render(<App items={c} />, scratch);
1658+
expect(scratch.innerHTML).to.equal(
1659+
`<div>${c.map(n => `<div>${n}</div>`).join('')}</div>`
1660+
);
1661+
expect(getLog()).to.deep.equal([
1662+
'<div>.appendChild(#text)',
1663+
'<div>1352640.insertBefore(<div>11, <div>1)',
1664+
'<div>111352640.insertBefore(<div>1, <div>5)',
1665+
'<div>113152640.insertBefore(<div>6, <div>0)',
1666+
'<div>113152460.insertBefore(<div>2, <div>0)',
1667+
'<div>113154620.insertBefore(<div>5, <div>0)',
1668+
'<div>.appendChild(#text)',
1669+
'<div>113146250.appendChild(<div>9)',
1670+
'<div>.appendChild(#text)',
1671+
'<div>1131462509.appendChild(<div>10)'
1672+
]);
1673+
clearLog();
16481674

16491675
render(<App items={a} />, scratch);
16501676
expect(scratch.innerHTML).to.equal(
16511677
`<div>${a.map(n => `<div>${n}</div>`).join('')}</div>`
16521678
);
1679+
expect(getLog()).to.deep.equal([
1680+
'<div>11.remove()',
1681+
'<div>9.remove()',
1682+
'<div>10.remove()',
1683+
'<div>3146250.appendChild(<div>1)',
1684+
'<div>3462501.appendChild(<div>2)',
1685+
'<div>3465012.appendChild(<div>3)',
1686+
'<div>4650123.appendChild(<div>4)',
1687+
'<div>6501234.appendChild(<div>5)',
1688+
'<div>6012345.appendChild(<div>6)'
1689+
]);
1690+
clearLog();
16531691
});
16541692
});

0 commit comments

Comments
 (0)