@@ -36,33 +36,54 @@ function Button( props: mim.IHtmlButtonElementProps, children: any[]): any
36
36
37
37
class Main extends mim . Component
38
38
{
39
- nextID = 1 ;
40
-
41
- // Flat array of Row components
42
39
private rows : Row [ ] = null ;
43
-
44
- // Currently selected Row component
45
40
public selectedRow : Row = undefined ;
41
+ private vnTBody : mim . IElmVN < HTMLElement > ;
46
42
43
+ public render ( )
44
+ {
45
+ return ( < div class = "container" >
46
+ < div class = "jumbotron" >
47
+ < div class = "row" >
48
+ < div class = "col-md-6" >
49
+ < h1 > Mimbl (keyed)</ h1 >
50
+ </ div >
51
+ < div class = "col-md-6" >
52
+ < div class = "row" >
53
+ < Button id = "run" click = { this . onCreate1000 } > Create 1,000 rows</ Button >
54
+ < Button id = "runlots" click = { this . onCreate10000 } > Create 10,000 rows</ Button >
55
+ < Button id = "add" click = { this . onAppend1000 } > Append 1,000 rows</ Button >
56
+ < Button id = "update" click = { this . onUpdateEvery10th } > Update every 10th row</ Button >
57
+ < Button id = "clear" click = { this . onClear } > Clear</ Button >
58
+ < Button id = "swaprows" click = { this . onSwapRows } > Swap Rows</ Button >
59
+ </ div >
60
+ </ div >
61
+ </ div >
62
+ </ div >
63
+ < table class = "table table-hover table-striped test-data" >
64
+ < tbody vnref = { ( r ) => this . vnTBody = r } updateStrategy = { { disableKeyedNodeRecycling : true } } >
65
+ { this . rows }
66
+ </ tbody >
67
+ </ table >
68
+ < span class = "preloadicon glyphicon glyphicon-remove" aria-hidden = "true" > </ span >
69
+ </ div > ) ;
70
+ }
47
71
48
-
49
- onCreate1000 ( )
72
+ private onCreate1000 ( )
50
73
{
51
74
this . rows = buildRows ( this , 1000 ) ;
52
75
this . selectedRow = undefined ;
53
- this . updateMe ( this . renderRows ) ;
54
- // this.vnRefTBody.r.setChildren( this.rows);
76
+ this . vnTBody . setChildren ( this . rows ) ;
55
77
}
56
78
57
- onAppend1000 ( )
79
+ private onAppend1000 ( )
58
80
{
59
81
let newRows = buildRows ( this , 1000 ) ;
60
82
this . rows = this . rows ? this . rows . concat ( newRows ) : newRows ;
61
- this . updateMe ( this . renderRows ) ;
62
- // this.vnRefTBody.r.setChildren( this.rows);
83
+ this . vnTBody . growChildren ( undefined , newRows ) ;
63
84
}
64
85
65
- onUpdateEvery10th ( )
86
+ private onUpdateEvery10th ( )
66
87
{
67
88
if ( ! this . rows )
68
89
return ;
@@ -71,99 +92,53 @@ class Main extends mim.Component
71
92
this . rows [ i ] . updateLabel ( )
72
93
}
73
94
74
- onCreate10000 ( )
95
+ private onCreate10000 ( )
75
96
{
76
97
this . rows = buildRows ( this , 10000 ) ;
77
98
this . selectedRow = undefined ;
78
- this . updateMe ( this . renderRows ) ;
79
- // this.vnRefTBody.r.setChildren( this.rows);
99
+ this . vnTBody . setChildren ( this . rows ) ;
80
100
}
81
101
82
- onClear ( )
102
+ private onClear ( )
83
103
{
84
104
this . rows = null ;
85
105
this . selectedRow = undefined ;
86
- this . updateMe ( this . renderRows ) ;
87
- // this.vnRefTBody.r.setChildren( this.rows);
106
+ this . vnTBody . setChildren ( null ) ;
88
107
}
89
108
90
- onSwapRows ( )
109
+ private onSwapRows ( )
91
110
{
92
111
if ( this . rows && this . rows . length > 998 )
93
112
{
94
113
let t = this . rows [ 1 ] ;
95
114
this . rows [ 1 ] = this . rows [ 998 ] ;
96
115
this . rows [ 998 ] = t ;
97
- this . updateMe ( this . renderRows ) ;
98
- // this.vnRefTBody.r.setChildren( this.rows);
116
+ this . vnTBody . swapChildren ( 1 , 1 , 998 , 1 ) ;
99
117
}
100
118
}
101
119
102
- onSelectRowClicked ( rowToSelect : Row )
120
+ public onSelectRowClicked ( rowToSelect : Row )
103
121
{
104
122
if ( rowToSelect === this . selectedRow )
105
123
return ;
106
124
107
125
if ( this . selectedRow )
108
- this . selectedRow . select ( false ) ;
126
+ this . selectedRow . trVN . setProps ( { class : undefined } ) ;
109
127
110
128
this . selectedRow = rowToSelect ;
111
- rowToSelect . select ( true ) ;
129
+ this . selectedRow . trVN . setProps ( { class : "danger" } ) ;
112
130
}
113
131
114
- onDeleteRowClicked ( rowToDelete : Row )
132
+ public onDeleteRowClicked ( rowToDelete : Row )
115
133
{
116
134
if ( rowToDelete === this . selectedRow )
117
135
this . selectedRow = undefined ;
118
136
119
137
let id = rowToDelete . id ;
120
138
let i = this . rows . findIndex ( row => row . id == id ) ;
121
139
this . rows . splice ( i , 1 ) ;
122
- this . updateMe ( this . renderRows ) ;
123
- // this.vnRefTBody.r.setChildren( this.rows);
140
+ this . vnTBody . spliceChildren ( i , 1 ) ;
124
141
}
125
-
126
- render ( )
127
- {
128
- return ( < div class = "container" >
129
- < div class = "jumbotron" >
130
- < div class = "row" >
131
- < div class = "col-md-6" >
132
- < h1 > Mimbl (keyed)</ h1 >
133
- </ div >
134
- < div class = "col-md-6" >
135
- < div class = "row" >
136
- < Button id = "run" click = { this . onCreate1000 } > Create 1,000 rows</ Button >
137
- < Button id = "runlots" click = { this . onCreate10000 } > Create 10,000 rows</ Button >
138
- < Button id = "add" click = { this . onAppend1000 } > Append 1,000 rows</ Button >
139
- < Button id = "update" click = { this . onUpdateEvery10th } > Update every 10th row</ Button >
140
- < Button id = "clear" click = { this . onClear } > Clear</ Button >
141
- < Button id = "swaprows" click = { this . onSwapRows } > Swap Rows</ Button >
142
- </ div >
143
- </ div >
144
- </ div >
145
- </ div >
146
- < table class = "table table-hover table-striped test-data" >
147
- { this . renderRows }
148
- { /* <tbody vnref={this.vnRefTBody} updateStrategy={{disableKeyedNodeRecycling: true}}>
149
- {this.rows}
150
- </tbody> */ }
151
- </ table >
152
- < span class = "preloadicon glyphicon glyphicon-remove" aria-hidden = "true" > </ span >
153
- </ div > ) ;
154
- }
155
-
156
- @mim . noWatcher renderRows ( )
157
- {
158
- if ( ! this . rows )
159
- return null ;
160
-
161
- return < tbody updateStrategy = { { disableKeyedNodeRecycling : true } } >
162
- { this . rows }
163
- </ tbody >
164
- }
165
-
166
- // private vnRefTBody = new mim.ElmRef<HTMLElement>();
167
142
}
168
143
169
144
let glyphVN = < span class = "glyphicon glyphicon-remove" aria-hidden = "true" /> ;
@@ -173,8 +148,7 @@ class Row extends mim.Component
173
148
{
174
149
main : Main ;
175
150
id : number ;
176
- label : string ;
177
- // trRef = new mim.ElmRef<HTMLTableRowElement>();
151
+ // label: string;
178
152
labelVN : mim . ITextVN ;
179
153
trVN : mim . IElmVN < HTMLTableRowElement > ;
180
154
@@ -184,52 +158,41 @@ class Row extends mim.Component
184
158
185
159
this . main = main ;
186
160
this . id = id ;
187
- this . label = label ;
161
+ // this.label = label;
188
162
this . labelVN = mim . createTextVN ( label ) ;
189
163
}
190
164
191
- willMount ( )
165
+ public willMount ( )
192
166
{
193
- this . trVN = < tr class = { this . main . selectedRow === this ? "danger" : undefined } >
167
+ this . trVN = < tr >
194
168
< td class = "col-md-1" > { this . id } </ td >
195
- < td class = "col-md-4" > < a click = { { func : this . onSelectClicked , schedulingType : "s" } } > { this . labelVN } </ a > </ td >
169
+ < td class = "col-md-4" > < a click = { this . onSelectClicked } > { this . labelVN } </ a > </ td >
196
170
< td class = "col-md-1" > < a click = { this . onDeleteClicked } > { glyphVN } </ a > </ td >
197
171
{ lastCellVN }
198
172
</ tr > as mim . IElmVN < HTMLTableRowElement > ;
199
173
}
200
174
201
- updateLabel ( )
175
+ @mim . noWatcher
176
+ public render ( )
202
177
{
203
- this . label += " !!!" ;
204
- this . labelVN . setText ( this . label ) ;
178
+ return this . trVN ;
205
179
}
206
180
207
- select ( selected : boolean )
181
+ public updateLabel ( )
208
182
{
209
- // this.trRef.r.setProps( {class: selected ? "danger" : undefined} );
210
- this . trVN . setProps ( { class : selected ? "danger" : undefined } ) ;
183
+ // this.labelVN.setText( this.label += " !!!" );
184
+ this . labelVN . setText ( this . labelVN . text + " !!!" ) ;
211
185
}
212
186
213
- onDeleteClicked ( )
187
+ private onDeleteClicked ( )
214
188
{
215
189
this . main . onDeleteRowClicked ( this ) ;
216
190
}
217
191
218
- onSelectClicked ( )
192
+ private onSelectClicked ( )
219
193
{
220
194
this . main . onSelectRowClicked ( this ) ;
221
195
}
222
-
223
- @mim . noWatcher render ( )
224
- {
225
- return this . trVN ;
226
- // return <tr vnref={this.trRef} class={this.main.selectedRow === this ? "danger" : undefined}>
227
- // <td class="col-md-1">{this.id}</td>
228
- // <td class="col-md-4"><a click={this.onSelectClicked}>{this.labelVN}</a></td>
229
- // <td class="col-md-1"><a click={this.onDeleteClicked}>{glyphVN}</a></td>
230
- // {lastCellVN}
231
- // </tr>;
232
- }
233
196
}
234
197
235
198
0 commit comments