@@ -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 ( ) {
@@ -69,25 +71,57 @@ Doo.define(
69
71
run ( ) {
70
72
this . data . rows = this . buildData ( )
71
73
this . renderTable ( )
74
+ if ( this . tbody . childNodes . length > this . data . rows . length ) {
75
+ this . tbody . textContent = ''
76
+ }
77
+
78
+ }
79
+ run ( e ) {
80
+ Timer . start ( 'tot' )
81
+ this . data . rows = this . buildData ( )
82
+ if ( this . tbody . childNodes . length > this . data . rows . length ) {
83
+ this . tbody . textContent = ''
84
+ }
85
+ this . renderTable ( )
86
+ // e.target.blur()
87
+ Timer . stop ( 'tot' )
72
88
}
73
89
74
- add ( ) {
90
+ add ( e ) {
91
+ Timer . start ( 'tot' )
75
92
let startRow = this . data . rows . length
76
93
this . data . rows = this . data . rows . concat ( this . buildData ( ) )
77
94
this . renderTable ( this . data . rows , startRow )
78
- }
95
+ Timer . stop ( 'tot' )
96
+
97
+ }
79
98
80
- runLots ( ) {
99
+
100
+ runLots ( e ) {
101
+ this . data . rows = this . buildData ( 10000 )
102
+ if ( this . tbody . childNodes . length > this . data . rows . length ) {
103
+ this . tbody . textContent = ''
104
+ }
105
+ this . renderTable ( )
106
+ }
107
+
108
+ runLots ( e ) {
109
+ Timer . start ( 'tot' )
81
110
this . data . rows = this . buildData ( 10000 )
111
+ if ( this . tbody . childNodes . length > this . data . rows . length ) {
112
+ this . tbody . textContent = ''
113
+ }
82
114
this . renderTable ( )
115
+ // e.target.blur()
116
+ Timer . stop ( 'tot' )
83
117
}
84
118
85
- update ( ) {
86
- let tr = this . tbody . querySelectorAll ( 'tr ')
119
+ update ( e ) {
120
+ Timer . start ( 'tot ')
87
121
for ( let i = 0 , len = this . data . rows . length ; i < len ; i += 10 ) {
88
- this . data . rows [ i ] . label += ' !!!' ;
89
- tr [ i ] . childNodes [ 1 ] . childNodes [ 0 ] . textContent = this . data . rows [ i ] . label
122
+ this . tbody . childNodes [ i ] . childNodes [ 1 ] . childNodes [ 0 ] . innerText = this . data . rows [ i ] . label += ' !!!'
90
123
}
124
+ Timer . stop ( 'tot' )
91
125
}
92
126
93
127
select ( elem ) {
@@ -118,25 +152,24 @@ Doo.define(
118
152
119
153
this . tbody . insertBefore ( node2 , node1 )
120
154
this . tbody . insertBefore ( node1 , this . tbody . childNodes [ 999 ] )
121
-
122
155
}
123
156
}
124
157
125
158
addEventListeners ( ) {
126
159
document . getElementById ( "main" ) . addEventListener ( 'click' , e => {
127
160
e . preventDefault ( ) ;
128
161
if ( e . target . matches ( '#runlots' ) ) {
129
- this . runLots ( ) ;
162
+ this . runLots ( e ) ;
130
163
} else if ( e . target . matches ( '#run' ) ) {
131
- this . run ( ) ;
164
+ this . run ( e ) ;
132
165
} else if ( e . target . matches ( '#add' ) ) {
133
- this . add ( ) ;
166
+ this . add ( e ) ;
134
167
} else if ( e . target . matches ( '#update' ) ) {
135
- this . update ( ) ;
168
+ this . update ( e ) ;
136
169
} else if ( e . target . matches ( '#clear' ) ) {
137
170
this . clear ( ) ;
138
171
} else if ( e . target . matches ( '#swaprows' ) ) {
139
- this . swapRows ( ) ;
172
+ this . swapRows ( e ) ;
140
173
}
141
174
} )
142
175
}
0 commit comments