1
1
'use strict' ;
2
2
3
- let startTime = { } ;
4
- let tot = [ ]
5
-
6
-
7
3
const _random = ( ( max ) => {
8
4
return Math . round ( Math . random ( ) * 1000 ) % max ;
9
5
} )
@@ -32,9 +28,9 @@ Doo.define(
32
28
this . swaprows = this . swapRows . bind ( this )
33
29
this . addEventListeners ( )
34
30
this . selectedRow = undefined
35
- document . querySelector ( ".jumbotron H1 " ) . innerHTML += ` ${ Doo . version } (keyed)`
31
+ document . querySelector ( ".ver " ) . innerHTML += ` ${ Doo . version } (keyed)`
36
32
document . title += ` ${ Doo . version } (keyed)`
37
- }
33
+ }
38
34
39
35
async dooAfterRender ( ) {
40
36
this . tbody = this . shadow . querySelector ( '#tbody' )
@@ -47,8 +43,8 @@ Doo.define(
47
43
}
48
44
} ) ;
49
45
}
50
-
51
- getParentRow ( elem ) {
46
+
47
+ getParentRow ( elem ) {
52
48
while ( elem ) {
53
49
if ( elem . tagName === "TR" ) { return elem }
54
50
elem = elem . parentNode ;
@@ -63,7 +59,7 @@ Doo.define(
63
59
}
64
60
return data
65
61
}
66
-
62
+
67
63
delete ( elem ) {
68
64
let row = this . getParentRow ( elem )
69
65
if ( row ) {
@@ -74,18 +70,20 @@ Doo.define(
74
70
75
71
run ( ) {
76
72
this . data . rows = this . buildData ( )
77
- this . renderAll ( )
73
+ this . tbody . textContent = ''
74
+ this . renderTable ( )
78
75
}
79
76
80
77
add ( ) {
81
78
let len = this . data . rows . length
82
79
this . data . rows = this . data . rows . concat ( this . buildData ( ) )
83
- this . appendData ( this . data . rows , len )
80
+ this . appendData ( this . data . rows , len , 1000 )
84
81
}
85
82
86
83
runLots ( ) {
87
- this . data . rows = this . buildData ( 10000 ) ;
88
- this . renderAll ( )
84
+ this . data . rows = this . buildData ( 10000 )
85
+ this . tbody . textContent = ''
86
+ this . renderTable ( )
89
87
}
90
88
91
89
update ( ) {
@@ -111,32 +109,33 @@ Doo.define(
111
109
112
110
clear ( ) {
113
111
this . data . rows = [ ]
114
- this . tbody . textContent = ''
112
+ this . tbody . innerHTML = ''
115
113
}
116
114
117
115
swapRows ( ) {
118
116
if ( this . data . rows . length > 10 ) {
119
- let tr = this . tbody . querySelectorAll ( 'tr' )
120
- let swapNodeIdx = Math . min ( tr . length - 2 , 998 )
121
- let node1 = tr [ 1 ] . cloneNode ( true )
122
- let node2 = tr [ swapNodeIdx ] . cloneNode ( true )
123
- let tmp = this . data . rows [ 1 ]
124
- this . data . rows [ 1 ] = this . data . rows [ swapNodeIdx ] ;
125
- this . data . rows [ swapNodeIdx ] = tmp ;
126
- this . tbody . replaceChild ( node2 , tr [ 1 ] )
127
- this . tbody . replaceChild ( node1 , tr [ swapNodeIdx ] )
117
+ let node1 = this . tbody . childNodes [ 1 ]
118
+ let node2 = this . tbody . childNodes [ 998 ]
119
+
120
+ let row1 = this . data . rows [ 1 ] ;
121
+ this . data . rows [ 1 ] = this . data . rows [ 998 ] ;
122
+ this . data . rows [ 998 ] = row1
123
+
124
+ this . tbody . insertBefore ( node2 , node1 )
125
+ this . tbody . insertBefore ( node1 , this . tbody . childNodes [ 999 ] )
126
+
128
127
}
129
128
}
130
129
131
130
addEventListeners ( ) {
132
131
document . getElementById ( "main" ) . addEventListener ( 'click' , e => {
133
132
e . preventDefault ( ) ;
134
133
if ( e . target . matches ( '#runlots' ) ) {
135
- this . runLots ( ) ;
134
+ this . runLots ( e ) ;
136
135
} else if ( e . target . matches ( '#run' ) ) {
137
- this . run ( ) ;
136
+ this . run ( e ) ;
138
137
} else if ( e . target . matches ( '#add' ) ) {
139
- this . add ( ) ;
138
+ this . add ( e ) ;
140
139
} else if ( e . target . matches ( '#update' ) ) {
141
140
this . update ( ) ;
142
141
} else if ( e . target . matches ( '#clear' ) ) {
0 commit comments