Skip to content

Commit 1dd63dd

Browse files
author
Henrik jJaven
committed
better swap
1 parent 73a12a3 commit 1dd63dd

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

frameworks/non-keyed/doohtml/js/Main.class.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,35 @@ Doo.define(
110110
this.tbody.textContent = ''
111111
}
112112

113+
isRowSelected(elem) {
114+
return elem.classList.contains('danger')
115+
}
113116
swapRows() {
114-
if (this.data.rows.length > 998) {
115-
let node1 = this.tbody.firstChild.nextSibling,
116-
node2 = node1.nextSibling,
117-
node998 = this.tbody.childNodes[998],
118-
node999 = node998.nextSibling,
119-
row1 = this.data.rows[1]
117+
const A=1,B=998
118+
if (this.data.rows.length > B) {
120119

121-
this.data.rows[1] = this.data.rows[998];
122-
this.data.rows[998] = row1
120+
let a = this.tbody.childNodes[A],
121+
b = this.tbody.childNodes[B],
122+
row1 = this.data.rows[1]
123123

124-
this.tbody.insertBefore(node998, node2)
125-
this.tbody.insertBefore(node1, node999)
124+
this.data.rows[A] = this.data.rows[B];
125+
this.data.rows[B] = row1
126+
127+
const selected1 = this.isRowSelected(a)
128+
const selected2 = this.isRowSelected(b)
129+
this.updateRow(A, this.data.rows, this.tbody)
130+
this.updateRow(B, this.data.rows, this.tbody)
131+
132+
if (selected1) {
133+
this.select(this.tbody.childNodes[B])
134+
}
135+
if (selected2) {
136+
this.select(this.tbody.childNodes[A])
137+
}
126138
}
127139
}
128140

141+
129142
addEventListeners() {
130143
document.getElementById("main").addEventListener('click', e => {
131144
e.preventDefault()

frameworks/non-keyed/doohtml/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-framework-benchmark-doohtml",
3-
"version": "0.60.12",
3+
"version": "0.60.13",
44
"description": "DooHTML JS-Benchmark",
55
"main": "Main.class.js",
66
"js-framework-benchmark": {

0 commit comments

Comments
 (0)