Skip to content

Commit bfdcc27

Browse files
committed
Update Main.js
1 parent 15da226 commit bfdcc27

File tree

1 file changed

+15
-8
lines changed
  • frameworks/keyed/vanillajs-3/src

1 file changed

+15
-8
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
"use strict";
22

3-
class App {
3+
new class App {
44
index = 1; data = [];
55
tbody = document.getElementsByTagName('tbody')[0];
6+
constructor() {
7+
this.tbody.onclick = app.onclick();
8+
for (let key of ['run', 'runlots', 'add', 'update', 'clear', 'swaprows']) {
9+
document.getElementById(key).onclick = (e) => { e.stopPropagation(); this[key](); }
10+
}
11+
};
612
run(n = 1000) { if (this.data.length) this.clear(); this.add(n); };
713
runlots() { this.run(10000) };
814
add(n = 1000) {
@@ -34,7 +40,13 @@ class App {
3440
};
3541
update() {
3642
const children = this.tbody.children, data = this.data;
37-
for (let i = 0; i < this.data.length; i+=10) children[i].querySelector('a.lbl').firstChild.nodeValue = this.data[i] = `${this.data[i]} !!!`
43+
let child, lbl;
44+
for (let i = 0; i < this.data.length; i+=10) {
45+
child = children[i];
46+
if (child.hasOwnProperty('lbl')) lbl = child.lbl;
47+
else child.lbl = lbl = children[i].querySelector('a.lbl').firstChild;
48+
lbl.nodeValue = this.data[i] = `${this.data[i]} !!!`
49+
}
3850
};
3951
clear() { this.tbody.textContent = ''; this.data = [] };
4052

@@ -65,9 +77,4 @@ class App {
6577
}
6678
}
6779
}
68-
}
69-
const app = new App();
70-
tbody.onclick = app.onclick();
71-
for (let key of ['run', 'runlots', 'add', 'update', 'clear', 'swaprows']) {
72-
document.getElementById(key).onclick = (e) => { e.stopPropagation(); app[key](); }
73-
}
80+
}();

0 commit comments

Comments
 (0)