Skip to content

Commit de13328

Browse files
committed
Merge branch 'master' of https://github.com/syduki/js-framework-benchmark into syduki-master
2 parents 86bdd98 + b0c39ad commit de13328

File tree

1 file changed

+18
-24
lines changed
  • frameworks/keyed/vanillajs-lite/src

1 file changed

+18
-24
lines changed

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

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,49 @@ const colours = ['red', 'yellow', 'blue', 'green', 'pink', 'brown', 'purple', 'b
33
const nouns = ['table', 'chair', 'house', 'bbq', 'desk', 'car', 'pony', 'cookie', 'sandwich', 'burger', 'pizza', 'mouse', 'keyboard'];
44

55
const pick = dict => dict[Math.round(Math.random() * 1000) % dict.length];
6-
const label = () =>`${pick(adjectives)} ${pick(colours)} ${pick(nouns)}`;
6+
const label = () => `${pick(adjectives)} ${pick(colours)} ${pick(nouns)}`;
77
const labelOf = r => r.firstChild.nextSibling.firstChild.firstChild;
88

9-
const [[table], [tbody], [trow], buttons] = 'table,tbody,#trow,button'
10-
.split(',').map(s => document.querySelectorAll(s));
11-
const {children: rows} = tbody;
9+
let ID = 1, SEL, TMPL, SIZE;
10+
const [[TABLE], [TBODY], [TROW], BUTTONS] = 'table,tbody,#trow,button'
11+
.split(',').map(s => document.querySelectorAll(s)), ROWS = TBODY.children;
1212

1313
const {cloneNode, insertBefore} = Node.prototype;
1414
const clone = n => cloneNode.call(n, true);
15-
const insert = insertBefore.bind(tbody);
16-
17-
let ID = 1, SEL, TMPL, SIZE;
18-
15+
const insert = insertBefore.bind(TBODY);
1916
const create = (count, add) => {
2017
if (SIZE !== count)
21-
TMPL = clone(trow.content), [...Array((SIZE = count) / 50 - 1)]
18+
TMPL = clone(TROW.content), [...Array((SIZE = count) / 50 - 1)]
2219
.forEach(() => TMPL.appendChild(clone(TMPL.firstChild)));
23-
!add && (clear(), tbody.remove());
20+
!add && (clear(), TBODY.remove());
2421
while (count) {
25-
for (let r of TMPL.children)
22+
for (const r of TMPL.children)
2623
(r.$id ??= r.firstChild.firstChild).nodeValue = ID++,
2724
(r.$label ??= labelOf(r)).nodeValue = label(), count--;
2825
insert(clone(TMPL), null);
2926
}
30-
!add && table.appendChild(tbody);
27+
!add && TABLE.appendChild(TBODY);
3128
};
29+
const clear = () => (TBODY.textContent = '', SEL = null);
3230

33-
const clear = () => (tbody.textContent = '', SEL = null);
34-
35-
buttons.forEach(function (b) { b.onclick = this[b.id]; }, {
31+
BUTTONS.forEach(function (b) { b.onclick = this[b.id]; }, {
3632
run () { create(1000); },
3733
runlots () { create(10000); },
3834
add () { create(1000, true); },
3935
clear,
4036
update () {
41-
for (let i = 0; i < rows.length; i += 10)
42-
labelOf(rows[i]).nodeValue += ' !!!';
37+
for (let i = 0, r; r = ROWS[i]; i += 10)
38+
labelOf(r).nodeValue += ' !!!';
4339
},
4440
swaprows () {
45-
const [, r1, r2] = rows, r998 = rows[998];
41+
const [, r1, r2] = ROWS, r998 = ROWS[998];
4642
r998 && (insert(r1, r998), insert(r998, r2));
4743
}
4844
});
4945

50-
tbody.onclick = e => {
51-
const t = e.target, r = t.closest('tr');
52-
const td2 = r?.firstChild.nextSibling, td3 = td2?.nextSibling;
46+
TBODY.onclick = e => {
47+
const t = e.target, n = t.tagName, r = t.closest('TR');
5348
e.stopPropagation();
54-
t === td2?.firstChild ?
55-
(SEL && (SEL.className = ''), (SEL = r).className = 'danger') :
56-
(t === td3?.firstChild || t === td3?.firstChild.firstChild) && r.remove();
49+
(n == 'SPAN' || n == 'A' && t.firstElementChild) ? r.remove() :
50+
n == 'A' && (SEL && (SEL.className = ''), (SEL = r).className = 'danger');
5751
};

0 commit comments

Comments
 (0)