1
1
use rand:: prelude:: * ;
2
- use sauron:: prelude :: * ;
2
+ use sauron:: * ;
3
3
use std:: cmp:: min;
4
- use web_sys:: window;
5
4
6
5
static ADJECTIVES : & [ & str ] = & [
7
6
"pretty" ,
@@ -158,7 +157,7 @@ impl Application<Msg> for App {
158
157
159
158
node ! {
160
159
<div class="container" >
161
- { jumbotron_view ( ) }
160
+ { self . view_jumbotron ( ) }
162
161
<table class="table table-hover table-striped test-data" >
163
162
<tbody id="tbody" >
164
163
{ for r in rows { r } }
@@ -170,79 +169,78 @@ impl Application<Msg> for App {
170
169
}
171
170
}
172
171
173
- pub struct Jumbotron ;
174
-
175
- fn jumbotron_view ( ) -> Node < Msg > {
176
- node ! {
177
- <div class="jumbotron " >
178
- <div class="row " >
179
- <div class= "col-md-6" >
180
- <h1> { text ( "Sauron" ) } </h1 >
181
- </ div>
182
- <div class="col-md-6 " >
183
- <div class="row " >
184
- <div class= "col-sm-6 smallpad" >
185
- < button
186
- type = "button "
187
- id= "run "
188
- class= "btn btn-primary btn-block"
189
- on_click= { |_| Msg :: Run ( 1_000 ) } >
190
- { text ( "Create 1,000 rows" ) }
191
- </button >
192
- </ div>
193
- <div class= "col-sm-6 smallpad" >
194
- < button
195
- type = "button "
196
- class= "btn btn-primary btn-block"
197
- on_click= { |_| Msg :: Run ( 10_000 ) }
198
- id= "runlots" >
199
- { text ( "Create 10,000 rows" ) }
200
- </button >
201
- </ div>
202
- <div class= "col-sm-6 smallpad" >
203
- < button
204
- type = "button "
205
- class= "btn btn-primary btn-block"
206
- on_click= { |_| Msg :: Add ( 1_000 ) } id= "add" >
207
- { text ( "Append 1,000 rows" ) }
208
- </button >
209
- </ div>
210
- <div class= "col-sm-6 smallpad" >
211
- < button
212
- type = "button "
213
- class= "btn btn-primary btn-block"
214
- on_click= { |_| Msg :: Update ( 10 ) }
215
- id= "update" >
216
- { text ( "Update every 10th row" ) }
217
- </button >
218
- </ div>
219
- <div class= "col-sm-6 smallpad" >
220
- < button
221
- type = "button "
222
- class= "btn btn-primary btn-block"
223
- on_click= { |_| Msg :: Clear } id= "clear" >
224
- { text ( "Clear" ) }
225
- </button >
226
- </ div>
227
- <div class= "col-sm-6 smallpad" >
228
- < button
229
- type = "button "
230
- class= "btn btn-primary btn-block"
231
- on_click= { |_| Msg :: Swap }
232
- id= "swaprows" >
233
- { text ( "Swap Rows" ) }
234
- </button >
172
+ impl App {
173
+ fn view_jumbotron ( & self ) -> Node < Msg > {
174
+ node ! {
175
+ <div class= "jumbotron" >
176
+ <div class="row " >
177
+ <div class="col-md-6 " >
178
+ <h1> Sauron </h1 >
179
+ </div >
180
+ < div class= "col-md-6" >
181
+ <div class="row " >
182
+ <div class="col-sm-6 smallpad " >
183
+ <button
184
+ type = " button"
185
+ id= "run "
186
+ class= "btn btn-primary btn-block "
187
+ on_click= { |_| Msg :: Run ( 1_000 ) } >
188
+ Create 1 , 000 rows
189
+ </button>
190
+ </div >
191
+ < div class= "col-sm-6 smallpad" >
192
+ <button
193
+ type = " button"
194
+ class= "btn btn-primary btn-block "
195
+ on_click= { |_| Msg :: Run ( 10_000 ) }
196
+ id= "runlots" >
197
+ Create 10 , 000 rows
198
+ </button>
199
+ </div >
200
+ < div class= "col-sm-6 smallpad" >
201
+ <button
202
+ type = " button"
203
+ class= "btn btn-primary btn-block "
204
+ on_click= { |_| Msg :: Add ( 1_000 ) } id= "add" >
205
+ Append 1 , 000 rows
206
+ </button>
207
+ </div >
208
+ < div class= "col-sm-6 smallpad" >
209
+ <button
210
+ type = " button"
211
+ class= "btn btn-primary btn-block "
212
+ on_click= { |_| Msg :: Update ( 10 ) }
213
+ id= "update" >
214
+ Update every 10 th row
215
+ </button>
216
+ </div >
217
+ < div class= "col-sm-6 smallpad" >
218
+ <button
219
+ type = " button"
220
+ class= "btn btn-primary btn-block "
221
+ on_click= { |_| Msg :: Clear } id= "clear" >
222
+ Clear
223
+ </button>
224
+ </div >
225
+ < div class= "col-sm-6 smallpad" >
226
+ <button
227
+ type = " button"
228
+ class= "btn btn-primary btn-block "
229
+ on_click= { |_| Msg :: Swap }
230
+ id= "swaprows" >
231
+ Swap Rows
232
+ </button>
233
+ </div >
235
234
</div>
236
235
</div>
237
236
</div>
238
237
</div>
239
- </div>
238
+ }
240
239
}
241
240
}
242
241
243
242
#[ wasm_bindgen( start) ]
244
243
pub fn start ( ) {
245
- let document = window ( ) . unwrap ( ) . document ( ) . unwrap ( ) ;
246
- let mount_el = document. query_selector ( "#main" ) . unwrap ( ) . unwrap ( ) ;
244
+ let mount_el = sauron:: document ( ) . query_selector ( "#main" ) . unwrap ( ) . unwrap ( ) ;
247
245
Program :: append_to_mount ( App :: new ( ) , & mount_el) ;
248
246
}
0 commit comments