Skip to content

Commit 82e10c0

Browse files
committed
Er sorry I introduced a bigger semantic bug in remove when fixing the first one
1 parent e440ef8 commit 82e10c0

File tree

2 files changed

+15
-17
lines changed
  • frameworks

2 files changed

+15
-17
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ function append(n = 1000) {
2828
}
2929
function update() {
3030
const labels = tbody.querySelectorAll('a.lbl'), length = labels.length;
31-
for (i = 0; i < length; i += 10) labels[i].firstChild.nodeValue = data[i] += ' !!!'
31+
for (i = 0; i < length; i += 10) labels[i].firstChild.nodeValue = data[i] = `${data[i]} !!!`
3232
}
33-
function clear() { (data = []) && (tbody.textContent = '') }
33+
function clear() { data = []; tbody.textContent = '' }
3434

3535
function swap() {
36-
if (tbody.children.length < 999) return; const first = tbody.firstElementChild;
36+
if (tbody.children.length < 999) return;
37+
const first = tbody.firstElementChild, c998 = tbody.children[998];
3738
[data[1], data[998]] = [data[998], data[1]];
38-
tbody.insertBefore(tbody.insertBefore(first.nextElementSibling,
39-
tbody.children[998]).nextElementSibling, first.nextElementSibling);
39+
tbody.insertBefore(tbody.insertBefore(first.nextElementSibling, c998) && c998,
40+
first.nextElementSibling);
4041
}
4142
tbody.onclick = (e) => {
4243
e.preventDefault; e.stopPropagation;
@@ -45,11 +46,12 @@ tbody.onclick = (e) => {
4546
if (element === selected) selected.className = selected.className ? "" : "danger";
4647
else {
4748
if (selected) selected.className = "";
48-
(element.className = "danger") && (selected = element)
49+
element.className = "danger"; selected = element;
4950
}
5051
} else if (e.target.matches('span.remove')) {
5152
const element = e.target.parentNode.parentNode.parentNode;
52-
data.splice(Array.prototype.indexOf.call(tbody.children, element)) && tbody.removeChild(element);
53+
data.splice(Array.prototype.indexOf.call(tbody.children, element), 1);
54+
tbody.removeChild(element);
5355
}
5456
}
5557
for (let [key, fn] of Object.entries({

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
const adjectives = ["pretty", "large", "big", "small", "tall", "short", "long", "handsome", "plain", "quaint", "clean", "elegant", "easy", "angry", "crazy", "helpful", "mushy", "odd", "unsightly", "adorable", "important", "inexpensive", "cheap", "expensive", "fancy"];
22
const colours = ["red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", "orange"];
33
const nouns = ["table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza", "mouse", "keyboard"];
4-
const lengths = [adjectives.length, colours.length, nouns.length];
5-
function* _random(n) {
6-
for (let max of lengths) {
7-
const arr = new Array(n);
8-
for (i = 0; i < n; i++) arr[i] = Math.round(Math.random() * 1000) % max;
9-
yield arr
10-
}
11-
}
4+
const [l1, l2, l3] = [adjectives.length, colours.length, nouns.length];
125
const data = [], nTemplates = (n) => Math.round(n / 100), tbody = document.getElementsByTagName('tbody')[0];
136
let index = 1, i, lbl, selected;
147

@@ -35,7 +28,7 @@ function set(n) {
3528
}
3629
}
3730
function append(n = 1000) {
38-
const [r1, r2, r3] = _random(n), nt = nTemplates(n); let j = 0;
31+
const nt = nTemplates(n); let j = 0, r1, r2, r3;
3932
const itemTemplate = document.getElementById('itemTemplate').content;
4033
while (nt >= itemTemplate.children.length * 2) itemTemplate.appendChild(itemTemplate.cloneNode(true));
4134
while (nt > itemTemplate.children.length) itemTemplate.appendChild(itemTemplate.firstElementChild.cloneNode(true));
@@ -45,6 +38,9 @@ function append(n = 1000) {
4538

4639
while ((n -= nt) >= 0) {
4740
for (i = 0; i < nt; i++, j++) {
41+
r1 = Math.round(Math.random() * 1000) % l1;
42+
r2 = Math.round(Math.random() * 1000) % l2;
43+
r3 = Math.round(Math.random() * 1000) % l3;
4844
ids[i].nodeValue = index++;
4945
data.push(labels[i].nodeValue = `${adjectives[r1[j]]} ${colours[r2[j]]} ${nouns[r3[j]]}`)
5046
}
@@ -53,7 +49,7 @@ function append(n = 1000) {
5349
}
5450
function update() {
5551
const labels = tbody.querySelectorAll('a.lbl'), length = labels.length;
56-
for (i = 0; i < length; i += 10) labels[i].firstChild.nodeValue = data[i] += ' !!!';
52+
for (i = 0; i < length; i += 10) labels[i].firstChild.nodeValue = data[i] = `${data[i]} !!!`;
5753
}
5854
function clear() { data.length = 0; tbody.textContent = '' }
5955

0 commit comments

Comments
 (0)