Skip to content

Commit ed7a947

Browse files
committed
Merge branch 'master' of https://github.com/syduki/js-framework-benchmark into syduki-master
2 parents fe425a2 + 1e6ac74 commit ed7a947

File tree

1 file changed

+12
-8
lines changed
  • frameworks/keyed/vanillajs-lite/src

1 file changed

+12
-8
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ let tbody = document.querySelector('tbody');
1212
const trow = document.querySelector('#trow');
1313

1414
const {cloneNode, insertBefore} = Node.prototype;
15-
const clone = (cloneNode.bind(trow.content.firstChild, true));
15+
const TBody = (cloneNode.bind(tbody, false));
16+
const TRow = (cloneNode.bind(trow.content.firstChild, true));
1617
const insert = ((row, before = null) => insertBefore.call(tbody, row, before));
1718

1819
const build = (() => {
19-
const tr = clone();
20+
const tr = TRow();
2021
const td1 = tr.firstChild, td2 = td1.nextSibling, td3 = td2.nextSibling;
2122
const a1 = td2.firstChild, a2 = td3.firstChild;
2223
const label = `${pick(adjectives)} ${pick(colours)} ${pick(nouns)}`;
@@ -36,19 +37,22 @@ const remove = (match => row => {
3637
rows = rows.filter(match, row), row.remove();
3738
})(function (row) { return row !== this; });
3839

39-
const clear = () => {
40+
const clear = patch => {
4041
rows = [], selection = null;
41-
const clone = tbody.cloneNode();
42-
tbody.remove(), insertBefore.call(table, tbody = clone, null);
42+
const empty = !tbody.firstChild;
43+
if (!empty || patch)
44+
!empty && patch ? (tbody.textContent = '', patch()) :
45+
(tbody.remove(), tbody = TBody(), patch?.(),
46+
insertBefore.call(table, tbody, null));
4347
};
4448

4549
document.querySelectorAll('button').forEach(function (button) {
4650
button.addEventListener('click', this[button.id]);
4751
}, {
48-
run () { clear(), rows = create(1000); },
49-
runlots () { clear(), rows = create(10000); },
52+
run () { clear(() => rows = create(1000)); },
53+
runlots () { clear(() => rows = create(10000)); },
5054
add () { rows = [...rows, ...create(1000)]; },
51-
clear,
55+
clear () { clear(); },
5256
update () {
5357
for (let i = 0; i < rows.length; i += 10)
5458
rows[i].label.nodeValue += ' !!!';

0 commit comments

Comments
 (0)