tangled
alpha
login
or
join now
yippee.fun
/
morphlex
0
fork
atom
Precise DOM morphing
morphing
typescript
dom
0
fork
atom
overview
issues
pulls
pipelines
Fix incorrect operation indexing.
joel.drapper.me
3 months ago
89b38001
cb64636e
+31
-1
2 changed files
expand all
collapse all
unified
split
src
morphlex.ts
test
new
reordering.browser.test.ts
+1
-1
src/morphlex.ts
···
691
691
const matchInd = matches[i]
692
692
if (matchInd !== undefined) {
693
693
const match = fromChildNodes[matchInd]!
694
694
-
const operation = op[matchInd]!
694
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
117
+
118
118
+
test("should use correct operation index when reordering with different operations", () => {
119
119
+
const from = dom(`
120
120
+
<div>
121
121
+
<span id="a" class="unchanged">A</span>
122
122
+
<span id="b" class="old-class">B</span>
123
123
+
</div>
124
124
+
`)
125
125
+
126
126
+
const to = dom(`
127
127
+
<div>
128
128
+
<span id="b" class="new-class">B</span>
129
129
+
<span id="a" class="unchanged">A</span>
130
130
+
</div>
131
131
+
`)
132
132
+
133
133
+
morph(from, to)
134
134
+
135
135
+
const children = Array.from(from.children) as HTMLSpanElement[]
136
136
+
137
137
+
expect(children.length).toBe(2)
138
138
+
expect(children[0]?.id).toBe("b")
139
139
+
expect(children[1]?.id).toBe("a")
140
140
+
141
141
+
expect(children[0]?.className).toBe("new-class")
142
142
+
expect(children[0]?.textContent).toBe("B")
143
143
+
144
144
+
expect(children[1]?.className).toBe("unchanged")
145
145
+
expect(children[1]?.textContent).toBe("A")
146
146
+
})
117
147
})