Skip to content

Commit 03043de

Browse files
committed
Morre improvements. Almost done.
1 parent 94367c9 commit 03043de

File tree

5 files changed

+235
-232
lines changed

5 files changed

+235
-232
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,6 @@ Cargo.lock
8383
*~
8484
frameworks/keyed/doohtml/js/doo.html.min.js.LICENSE.txt
8585
frameworks/non-keyed/doohtml/js/doo.html.min.js.LICENSE.txt
86+
87+
frameworks/keyed/vanillajs-4
88+

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

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ new class App {
1717
const nouns = ["table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza", "mouse", "keyboard"];
1818
const l1 = adjectives.length, l2 = colours.length,l3 = nouns.length;
1919

20-
const nt = Math.round(n / 100);
21-
const itemTemplate = document.getElementById('itemTemplate').content.cloneNode(true);
22-
20+
const itemTemplate = document.getElementById('itemTemplate').content; // .cloneNode(true);
21+
const nt = Math.max(itemTemplate.children.length, n / 100); // Math.round(n / 50);
22+
2323
while (nt >= itemTemplate.children.length * 2) itemTemplate.appendChild(itemTemplate.cloneNode(true));
2424
while (nt > itemTemplate.children.length) itemTemplate.appendChild(itemTemplate.firstElementChild.cloneNode(true));
2525

2626
const ids = Array.prototype.map.call(itemTemplate.querySelectorAll('td:first-child'), i => i.firstChild)
2727
const labels = Array.prototype.map.call(itemTemplate.querySelectorAll('a.lbl'), i => i.firstChild);
28-
28+
2929
let i, j = 0, r1, r2, r3;;
3030
while ((n -= nt) >= 0) {
3131
for (i = 0; i < nt; i++, j++) {
@@ -39,23 +39,18 @@ new class App {
3939
}
4040
};
4141
update() {
42-
const children = this.tbody.children, data = this.data;
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-
}
42+
const labels = this.tbody.querySelectorAll('tr:nth-child(10n+1)>td>a.lbl'), length = labels.length, data = this.data;
43+
let i = 0, lbl; for (lbl of labels) { lbl.firstChild.nodeValue = data[i] += ' !!!'; i += 10 }
5044
};
5145
clear() { this.tbody.textContent = ''; this.data = [] };
5246

5347
swaprows() {
54-
if (this.data.length < 999) return; // nb: swap does not affect labels
55-
const first = this.tbody.firstChild, sec = first.nextSibling,
56-
third = sec.nextSibling, c998 = this.tbody.children[998];
57-
this.tbody.insertBefore(this.tbody.insertBefore(sec, c998) && c998, third);
58-
const temp = this.data[1]; this.data[1] = this.data[998]; this.data[998] = temp;
48+
const tbody = this.tbody, data = this.data;
49+
if (tbody.children.length < 999) return;
50+
const first = tbody.firstElementChild;
51+
[data[1], data[998]] = [data[998], data[1]];
52+
tbody.insertBefore(tbody.insertBefore(first.nextElementSibling,
53+
tbody.children[998]).nextElementSibling, first.nextElementSibling);
5954
};
6055
onclick() {
6156
let selected;

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)