From c739eae5c9711f0f4d00842a454cde1c9d7824e9 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Wed, 19 Jun 2024 10:28:27 +0200 Subject: [PATCH] easier to read --- src/diff/children.js | 12 ++---------- test/browser/render.test.js | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/diff/children.js b/src/diff/children.js index eb86799efc..fb31e7b15c 100644 --- a/src/diff/children.js +++ b/src/diff/children.js @@ -320,16 +320,8 @@ function constructNewChildrenArray(newParentVNode, renderResult, oldChildren) { skew--; } } else if (matchingIndex < skewedIndex) { - // Our matched DOM-node is further in the negative way in the list of children - // than where it's at now. - - // When the remaining old chiildren is less than the new children - // plus our skewed index we know we are dealing with a growing list - if (remainingOldChildren < newChildrenLength + skewedIndex) { - skew += matchingIndex + skewedIndex; - } else { - skew = 0; - } + // When our new position is in front of our old position than we increase the skew + skew++; } // Move this VNode's DOM if the original index (matchingIndex) doesn't diff --git a/test/browser/render.test.js b/test/browser/render.test.js index e6caf3adb9..4755607c12 100644 --- a/test/browser/render.test.js +++ b/test/browser/render.test.js @@ -1636,7 +1636,9 @@ describe('render()', () => { ); const a = ['0', '1', '2', '3', '4', '5', '6']; const b = ['1', '3', '5', '2', '6', '4', '0']; + const c = ['11', '3', '1', '4', '6', '2', '5', '0', '9', '10']; render(, scratch); + clearLog(); expect(scratch.innerHTML).to.equal( `
${a.map(n => `
${n}
`).join('')}
` ); @@ -1645,10 +1647,46 @@ describe('render()', () => { expect(scratch.innerHTML).to.equal( `
${b.map(n => `
${n}
`).join('')}
` ); + expect(getLog()).to.deep.equal([ + '
0123456.insertBefore(
2,
6)', + '
0134526.appendChild(
4)', + '
0135264.appendChild(
0)' + ]); + clearLog(); + + render(, scratch); + expect(scratch.innerHTML).to.equal( + `
${c.map(n => `
${n}
`).join('')}
` + ); + expect(getLog()).to.deep.equal([ + '
.appendChild(#text)', + '
1352640.insertBefore(
11,
1)', + '
111352640.insertBefore(
1,
5)', + '
113152640.insertBefore(
6,
0)', + '
113152460.insertBefore(
2,
0)', + '
113154620.insertBefore(
5,
0)', + '
.appendChild(#text)', + '
113146250.appendChild(
9)', + '
.appendChild(#text)', + '
1131462509.appendChild(
10)' + ]); + clearLog(); render(, scratch); expect(scratch.innerHTML).to.equal( `
${a.map(n => `
${n}
`).join('')}
` ); + expect(getLog()).to.deep.equal([ + '
11.remove()', + '
9.remove()', + '
10.remove()', + '
3146250.appendChild(
1)', + '
3462501.appendChild(
2)', + '
3465012.appendChild(
3)', + '
4650123.appendChild(
4)', + '
6501234.appendChild(
5)', + '
6012345.appendChild(
6)' + ]); + clearLog(); }); });