@@ -8,6 +8,8 @@ const nouns = ["table", "chair", "house", "bbq", "desk", "car", "pony", "cookie"
8
8
9
9
const lenA = adjectives . length , lenB = colours . length , lenC = nouns . length
10
10
11
+ import Timer from './doo.timer.js'
12
+
11
13
Doo . define (
12
14
class Main extends Doo {
13
15
constructor ( ) {
@@ -27,7 +29,8 @@ Doo.define(
27
29
this . addEventListeners ( )
28
30
this . selectedRow = undefined
29
31
document . querySelector ( ".ver" ) . innerHTML += ` ${ Doo . version } (non-keyed)`
30
- document . title += ` ${ Doo . version } (non-keyed)` }
32
+ document . title += ` ${ Doo . version } (non-keyed)`
33
+ }
31
34
32
35
async dooAfterRender ( ) {
33
36
this . tbody = this . shadow . querySelector ( '#tbody' )
@@ -65,30 +68,80 @@ Doo.define(
65
68
}
66
69
}
67
70
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
+ }
68
97
run ( ) {
69
98
this . data . rows = this . buildData ( )
70
99
if ( this . tbody . childNodes . length > this . data . rows . length ) {
71
100
this . tbody . textContent = ''
72
101
}
73
102
this . renderTable ( )
103
+ }
74
104
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' )
75
114
}
76
115
77
- add ( ) {
116
+ add ( e ) {
117
+ Timer . start ( 'tot' )
78
118
let startRow = this . data . rows . length
79
119
this . data . rows = this . data . rows . concat ( this . buildData ( ) )
80
120
this . renderTable ( this . data . rows , startRow )
81
- }
121
+ Timer . stop ( 'tot' )
122
+
123
+ }
82
124
83
- runLots ( ) {
125
+ runLots ( e ) {
84
126
this . data . rows = this . buildData ( 10000 )
85
127
if ( this . tbody . childNodes . length > this . data . rows . length ) {
86
128
this . tbody . textContent = ''
87
129
}
88
130
this . renderTable ( )
89
131
}
90
132
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 ) {
92
145
for ( let i = 0 , len = this . data . rows . length ; i < len ; i += 10 ) {
93
146
this . tbody . childNodes [ i ] . childNodes [ 1 ] . childNodes [ 0 ] . innerText = this . data . rows [ i ] . label += ' !!!'
94
147
}
@@ -122,24 +175,25 @@ Doo.define(
122
175
123
176
this . tbody . insertBefore ( node2 , node1 )
124
177
this . tbody . insertBefore ( node1 , this . tbody . childNodes [ 999 ] )
178
+
125
179
}
126
180
}
127
181
128
182
addEventListeners ( ) {
129
183
document . getElementById ( "main" ) . addEventListener ( 'click' , e => {
130
184
e . preventDefault ( ) ;
131
185
if ( e . target . matches ( '#runlots' ) ) {
132
- this . runLots ( ) ;
186
+ this . runLots ( e ) ;
133
187
} else if ( e . target . matches ( '#run' ) ) {
134
- this . run ( ) ;
188
+ this . run ( e ) ;
135
189
} else if ( e . target . matches ( '#add' ) ) {
136
- this . add ( ) ;
190
+ this . add ( e ) ;
137
191
} else if ( e . target . matches ( '#update' ) ) {
138
- this . update ( ) ;
192
+ this . update ( e ) ;
139
193
} else if ( e . target . matches ( '#clear' ) ) {
140
194
this . clear ( ) ;
141
195
} else if ( e . target . matches ( '#swaprows' ) ) {
142
- this . swapRows ( ) ;
196
+ this . swapRows ( e ) ;
143
197
}
144
198
} )
145
199
}
0 commit comments