Skip to content

Commit 95c1003

Browse files
committed
Merge branch 'vanillajs-clonenode' of https://github.com/ryansolid/js-framework-benchmark into ryansolid-vanillajs-clonenode
2 parents 3d26177 + 860ea18 commit 95c1003

File tree

2 files changed

+16
-62
lines changed

2 files changed

+16
-62
lines changed

frameworks/keyed/vanillajs/src/Main.js

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ function _random(max) {
2222
return Math.round(Math.random()*1000)%max;
2323
}
2424

25+
const rowTemplate = document.createElement("tr");
26+
rowTemplate.innerHTML = "<td class='col-md-1'></td><td class='col-md-4'><a class='lbl'></a></td><td class='col-md-1'><a class='remove'><span class='remove glyphicon glyphicon-remove' aria-hidden='true'></span></a></td><td class='col-md-6'></td>";
27+
2528
class Store {
2629
constructor() {
2730
this.data = [];
@@ -91,12 +94,6 @@ class Store {
9194
}
9295
}
9396

94-
var td=function(className) {
95-
let td = document.createElement("td");
96-
td.className = className;
97-
return td;
98-
}
99-
10097
var getParentId = function(elem) {
10198
while (elem) {
10299
if (elem.tagName==="TR") {
@@ -343,32 +340,12 @@ class Main {
343340
}
344341
}
345342
createRow(data) {
346-
let tr = document.createElement("tr");
343+
const tr = rowTemplate.cloneNode(true),
344+
td1 = tr.firstChild,
345+
a2 = td1.nextSibling.firstChild;
347346
tr.data_id = data.id;
348-
let td1 = td("col-md-1");
349-
td1.innerText = data.id;
350-
tr.appendChild(td1);
351-
352-
let td2 = td("col-md-4")
353-
tr.appendChild(td2);
354-
let a2 = document.createElement("a");
355-
a2.className = "lbl";
356-
td2.appendChild(a2);
357-
a2.innerText = data.label;
358-
359-
let td3 = td("col-md-1");
360-
tr.appendChild(td3);
361-
let a = document.createElement("a");
362-
a.className = "remove";
363-
td3.appendChild(a);
364-
let span = document.createElement("span");
365-
span.className = "glyphicon glyphicon-remove remove";
366-
span.setAttribute("aria-hidden","true");
367-
a.appendChild(span);
368-
369-
let td5 = td("col-md-6");
370-
tr.appendChild(td5)
371-
347+
td1.textContent = data.id;
348+
a2.textContent = data.label;
372349
return tr;
373350
}
374351
}

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

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ function _random(max) {
2222
return Math.round(Math.random()*1000)%max;
2323
}
2424

25+
const rowTemplate = document.createElement("tr");
26+
rowTemplate.innerHTML = "<td class='col-md-1'></td><td class='col-md-4'><a class='lbl'></a></td><td class='col-md-1'><a class='remove'><span class='remove glyphicon glyphicon-remove' aria-hidden='true'></span></a></td><td class='col-md-6'></td>";
27+
2528
class Store {
2629
constructor() {
2730
this.data = [];
@@ -91,12 +94,6 @@ class Store {
9194
}
9295
}
9396

94-
var td=function(className) {
95-
let td = document.createElement("td");
96-
td.className = className;
97-
return td;
98-
}
99-
10097
var getParentId = function(elem) {
10198
while (elem) {
10299
if (elem.tagName==="TR") {
@@ -339,32 +336,12 @@ class Main {
339336
}
340337
}
341338
createRow(data) {
342-
let tr = document.createElement("tr");
339+
const tr = rowTemplate.cloneNode(true),
340+
td1 = tr.firstChild,
341+
a2 = td1.nextSibling.firstChild;
343342
tr.data_id = data.id;
344-
let td1 = td("col-md-1");
345-
td1.innerText = data.id;
346-
tr.appendChild(td1);
347-
348-
let td2 = td("col-md-4")
349-
tr.appendChild(td2);
350-
let a2 = document.createElement("a");
351-
a2.className = "lbl";
352-
td2.appendChild(a2);
353-
a2.innerText = data.label;
354-
355-
let td3 = td("col-md-1");
356-
tr.appendChild(td3);
357-
let a = document.createElement("a");
358-
a.className = "remove";
359-
td3.appendChild(a);
360-
let span = document.createElement("span");
361-
span.className = "glyphicon glyphicon-remove remove";
362-
span.setAttribute("aria-hidden","true");
363-
a.appendChild(span);
364-
365-
let td5 = td("col-md-6");
366-
tr.appendChild(td5)
367-
343+
td1.textContent = data.id;
344+
a2.textContent = data.label;
368345
return tr;
369346
}
370347
}

0 commit comments

Comments
 (0)