Skip to content

Commit b7718cf

Browse files
committed
I had some final ideas left to try
The changes further improve the performance of the implementation. This even shows some improvements for 1k rows.
1 parent b54764f commit b7718cf

File tree

1 file changed

+10
-10
lines changed
  • frameworks/keyed/vanillajs-3/src

1 file changed

+10
-10
lines changed

frameworks/keyed/vanillajs-3/src/Main.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ function* _random(n) {
1010
}
1111
}
1212
const data = [], tbody = document.getElementsByTagName('tbody')[0];
13-
let index = 1, i, lbl, selected, temp;
13+
let index = 1, i, lbl, selected;
1414

15-
function create(e, n = 1000) { if (data.length) clear(e); append(e, n); }
16-
function append(e, n = 1000) {
15+
function create(n = 1000) { if (data.length) clear(); append(n); }
16+
function append(n = 1000) {
1717
const [r1, r2, r3] = _random(n);
1818
const itemTemplate = document.getElementById('itemTemplate').content.firstElementChild;
1919
const itemId = itemTemplate.firstElementChild.firstChild, itemLabel = itemTemplate.querySelector('a.lbl').firstChild;
@@ -23,16 +23,16 @@ function append(e, n = 1000) {
2323
tbody.appendChild(itemTemplate.cloneNode(true));
2424
}
2525
}
26-
function update(e) {
26+
function update() {
2727
const labels = tbody.querySelectorAll('a.lbl'), length = labels.length;
2828
for (i = 0; i < length; i += 10) labels[i].firstChild.nodeValue = data[i] += ' !!!';
2929
}
30-
function clear(e) { data.length = 0; tbody.textContent = '' }
30+
function clear() { data.length = 0; tbody.textContent = '' }
3131

32-
function swap(e) {
33-
if (data.length < 999) return;
32+
function swap() {
33+
if (data.length < 999) return; let temp;
3434
[data[1], data[998]] = [data[998], data[1]];
35-
tbody.replaceChild(tbody.children[1], (temp = tbody.children[998]));
35+
tbody.insertBefore(tbody.children[1], (temp = tbody.children[998]));
3636
tbody.insertBefore(temp, tbody.children[1]);
3737
}
3838
tbody.onclick = (e) => {
@@ -49,6 +49,6 @@ tbody.onclick = (e) => {
4949
}
5050
}
5151
for (let [key, fn] of Object.entries({
52-
run: create, runlots: (e) => create(e, 10000),
52+
run: create, runlots: () => create(10000),
5353
add: append, update, clear, swaprows: swap
54-
})) document.getElementById(key).onclick = (e) => { e.stopPropagation(); fn(e) }
54+
})) document.getElementById(key).onclick = (e) => { e.stopPropagation(); fn() }

0 commit comments

Comments
 (0)