Precise DOM morphing
morphing typescript dom

Fix incorrect operation indexing.

+31 -1
+1 -1
src/morphlex.ts
··· 691 691 const matchInd = matches[i] 692 692 if (matchInd !== undefined) { 693 693 const match = fromChildNodes[matchInd]! 694 - const operation = op[matchInd]! 694 + const operation = op[i]! 695 695 696 696 if (!shouldNotMove[matchInd]) { 697 697 moveBefore(parent, match, insertionPoint)
+30
test/new/reordering.browser.test.ts
··· 114 114 expect(from.children[0]?.id).toBe("item-4") 115 115 expect(from.children[7]?.id).toBe("item-8") 116 116 }) 117 + 118 + test("should use correct operation index when reordering with different operations", () => { 119 + const from = dom(` 120 + <div> 121 + <span id="a" class="unchanged">A</span> 122 + <span id="b" class="old-class">B</span> 123 + </div> 124 + `) 125 + 126 + const to = dom(` 127 + <div> 128 + <span id="b" class="new-class">B</span> 129 + <span id="a" class="unchanged">A</span> 130 + </div> 131 + `) 132 + 133 + morph(from, to) 134 + 135 + const children = Array.from(from.children) as HTMLSpanElement[] 136 + 137 + expect(children.length).toBe(2) 138 + expect(children[0]?.id).toBe("b") 139 + expect(children[1]?.id).toBe("a") 140 + 141 + expect(children[0]?.className).toBe("new-class") 142 + expect(children[0]?.textContent).toBe("B") 143 + 144 + expect(children[1]?.className).toBe("unchanged") 145 + expect(children[1]?.textContent).toBe("A") 146 + }) 117 147 })