Skip to content

Commit 6e781dd

Browse files
author
Henrik jJaven
committed
Testing new table renderer
1 parent 244b6a6 commit 6e781dd

File tree

2 files changed

+83
-10
lines changed

2 files changed

+83
-10
lines changed

frameworks/non-keyed/doohtml/js/Main.class.js

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const nouns = ["table", "chair", "house", "bbq", "desk", "car", "pony", "cookie"
88

99
const lenA = adjectives.length, lenB = colours.length, lenC = nouns.length
1010

11+
import Timer from './doo.timer.js'
12+
1113
Doo.define(
1214
class Main extends Doo {
1315
constructor() {
@@ -27,7 +29,8 @@ Doo.define(
2729
this.addEventListeners()
2830
this.selectedRow = undefined
2931
document.querySelector(".ver").innerHTML += ` ${Doo.version} (non-keyed)`
30-
document.title += ` ${Doo.version} (non-keyed)` }
32+
document.title += ` ${Doo.version} (non-keyed)`
33+
}
3134

3235
async dooAfterRender() {
3336
this.tbody = this.shadow.querySelector('#tbody')
@@ -65,30 +68,80 @@ Doo.define(
6568
}
6669
}
6770

71+
renderTable(dataSet=this.data[this.defaultDataSet]) {
72+
let len = dataSet.length
73+
if (!this.xxx) {
74+
this.newParser(this.templateNode, dataSet[0])
75+
}
76+
let newElem;
77+
for (let i=0;i<len;i++) {
78+
79+
if (this.place[0].childNodes[i]) {
80+
newElem = this.place[0].childNodes[i]
81+
} else {
82+
newElem = this.xxx.cloneNode(true)
83+
this.place[0].appendChild(newElem)
84+
}
85+
for (const node of this.nodeArr) {
86+
if (node.type===1) {
87+
newElem.querySelector(node.selector).textContent = dataSet[i][node.fld]
88+
} else if (node.type===4) {
89+
let value = newElem.querySelector(node.selector).getAttribute(node.name).replace('{{' + node.fld + '}}', dataSet[i][node.fld])
90+
newElem.querySelector(node.selector).setAttribute(node.name, value)
91+
}
92+
}
93+
}
94+
95+
return
96+
}
6897
run() {
6998
this.data.rows = this.buildData()
7099
if (this.tbody.childNodes.length > this.data.rows.length) {
71100
this.tbody.textContent = ''
72101
}
73102
this.renderTable()
103+
}
74104

105+
run(e) {
106+
Timer.start('tot')
107+
this.data.rows = this.buildData()
108+
if (this.tbody.childNodes.length > this.data.rows.length) {
109+
this.tbody.textContent = ''
110+
}
111+
this.renderTable()
112+
// e.target.blur()
113+
Timer.stop('tot')
75114
}
76115

77-
add() {
116+
add(e) {
117+
Timer.start('tot')
78118
let startRow = this.data.rows.length
79119
this.data.rows = this.data.rows.concat(this.buildData())
80120
this.renderTable(this.data.rows, startRow)
81-
}
121+
Timer.stop('tot')
122+
123+
}
82124

83-
runLots() {
125+
runLots(e) {
84126
this.data.rows = this.buildData(10000)
85127
if (this.tbody.childNodes.length > this.data.rows.length) {
86128
this.tbody.textContent = ''
87129
}
88130
this.renderTable()
89131
}
90132

91-
update() {
133+
runLots(e) {
134+
Timer.start('tot')
135+
this.data.rows = this.buildData(10000)
136+
if (this.tbody.childNodes.length > this.data.rows.length) {
137+
this.tbody.textContent = ''
138+
}
139+
this.renderTable()
140+
// e.target.blur()
141+
Timer.stop('tot')
142+
}
143+
144+
update(e) {
92145
for (let i=0, len = this.data.rows.length;i<len;i+=10) {
93146
this.tbody.childNodes[i].childNodes[1].childNodes[0].innerText = this.data.rows[i].label += ' !!!'
94147
}
@@ -122,24 +175,25 @@ Doo.define(
122175

123176
this.tbody.insertBefore(node2, node1)
124177
this.tbody.insertBefore(node1, this.tbody.childNodes[999])
178+
125179
}
126180
}
127181

128182
addEventListeners() {
129183
document.getElementById("main").addEventListener('click', e => {
130184
e.preventDefault();
131185
if (e.target.matches('#runlots')) {
132-
this.runLots();
186+
this.runLots(e);
133187
} else if (e.target.matches('#run')) {
134-
this.run();
188+
this.run(e);
135189
} else if (e.target.matches('#add')) {
136-
this.add();
190+
this.add(e);
137191
} else if (e.target.matches('#update')) {
138-
this.update();
192+
this.update(e);
139193
} else if (e.target.matches('#clear')) {
140194
this.clear();
141195
} else if (e.target.matches('#swaprows')) {
142-
this.swapRows();
196+
this.swapRows(e);
143197
}
144198
})
145199
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export default class Timer {
2+
static time = new Object()
3+
4+
5+
static start(name) {
6+
7+
if (!Timer.time[name]) {
8+
Timer.time[name] = [ new Date().getTime()]
9+
}
10+
};
11+
static stop(name) {
12+
if (Timer.time[name]) {
13+
Timer.time[name].push(new Date().getTime())
14+
// console.log(name, ': ', Timer.time[name][1] - Timer.time[name][0]);
15+
if (name==='tot') document.title = (Timer.time[name][1] - Timer.time[name][0]) + '|' + document.title
16+
Timer.time[name] = undefined
17+
}
18+
};
19+
}

0 commit comments

Comments
 (0)