1
1
import { View , render } from "@dlightjs/dlight"
2
- import { buildData } from "./data"
2
+
3
+ let idCounter = 1
4
+
5
+ const adjectives = [ "pretty" , "large" , "big" , "small" , "tall" , "short" , "long" , "handsome" , "plain" , "quaint" , "clean" , "elegant" , "easy" , "angry" , "crazy" , "helpful" , "mushy" , "odd" , "unsightly" , "adorable" , "important" , "inexpensive" , "cheap" , "expensive" , "fancy" ]
6
+ const colours = [ "red" , "yellow" , "blue" , "green" , "pink" , "brown" , "purple" , "brown" , "white" , "black" , "orange" ]
7
+ const nouns = [ "table" , "chair" , "house" , "bbq" , "desk" , "car" , "pony" , "cookie" , "sandwich" , "burger" , "pizza" , "mouse" , "keyboard" ]
8
+
9
+ function _random ( max ) { return Math . round ( Math . random ( ) * 1000 ) % max } ;
10
+
11
+ function buildData ( count ) {
12
+ const data = new Array ( count )
13
+ for ( let i = 0 ; i < count ; i ++ ) {
14
+ data [ i ] = {
15
+ id : idCounter ++ ,
16
+ label : `${ adjectives [ _random ( adjectives . length ) ] } ${ colours [ _random ( colours . length ) ] } ${ nouns [ _random ( nouns . length ) ] } `
17
+ }
18
+ }
19
+ return data
20
+ }
3
21
4
22
@View
5
23
class Main {
@@ -11,9 +29,7 @@ class Main {
11
29
12
30
swapRows ( ) {
13
31
if ( this . rows . length > 998 ) {
14
- const tmp = this . rows [ 1 ]
15
- this . rows [ 1 ] = this . rows [ 998 ]
16
- this . rows [ 998 ] = tmp
32
+ [ this . rows [ 1 ] , this . rows [ 998 ] ] = [ this . rows [ 998 ] , this . rows [ 1 ] ]
17
33
this . rows = [ ...this . rows ]
18
34
}
19
35
}
@@ -27,20 +43,20 @@ class Main {
27
43
}
28
44
29
45
deleteRow ( id ) {
30
- this . rows = [ ... this . rows . filter ( row => row . id !== id ) ]
46
+ this . rows = this . rows . filter ( row => row . id !== id )
31
47
}
32
48
33
49
addBig ( ) {
34
50
this . rows = buildData ( 10000 )
35
51
}
36
52
37
53
append ( ) {
38
- this . rows = [ ... this . rows , ... buildData ( 1000 ) ]
54
+ this . rows = this . rows . concat ( buildData ( 1000 ) )
39
55
}
40
56
41
57
update ( ) {
42
58
for ( let i = 0 ; i < this . rows . length ; i += 10 ) {
43
- this . rows [ i ] = { ... this . rows [ i ] , label : this . rows [ i ] . label + " !!!" }
59
+ this . rows [ i ] . label += " !!!"
44
60
}
45
61
this . rows = [ ...this . rows ]
46
62
}
@@ -64,24 +80,12 @@ class Main {
64
80
}
65
81
div ( ) . class ( "col-md-6" ) ; {
66
82
div ( ) . class ( "row" ) ; {
67
- this . Button ( "Create 1,000 rows" )
68
- . onClick ( this . addRows )
69
- . id ( "run" )
70
- this . Button ( "Create 10,000 rows" )
71
- . onClick ( this . addBig )
72
- . id ( "runlots" )
73
- this . Button ( "Append 1,000 rows" )
74
- . onClick ( this . append )
75
- . id ( "add" )
76
- this . Button ( "Update every 10th rows" )
77
- . onClick ( this . update )
78
- . id ( "update" )
79
- this . Button ( "Clear" )
80
- . onClick ( this . clearRows )
81
- . id ( "clear" )
82
- this . Button ( "Swap Rows" )
83
- . onClick ( this . swapRows )
84
- . id ( "swaprows" )
83
+ this . Button ( "Create 1,000 rows" ) . onClick ( this . addRows ) . id ( "run" )
84
+ this . Button ( "Create 10,000 rows" ) . onClick ( this . addBig ) . id ( "runlots" )
85
+ this . Button ( "Append 1,000 rows" ) . onClick ( this . append ) . id ( "add" )
86
+ this . Button ( "Update every 10th rows" ) . onClick ( this . update ) . id ( "update" )
87
+ this . Button ( "Clear" ) . onClick ( this . clearRows ) . id ( "clear" )
88
+ this . Button ( "Swap Rows" ) . onClick ( this . swapRows ) . id ( "swaprows" )
85
89
}
86
90
}
87
91
}
@@ -93,8 +97,7 @@ class Main {
93
97
tr ( ) . class ( this . selectIdx === id ? "danger" : "" ) ; {
94
98
td ( id ) . class ( "col-md-1" )
95
99
td ( ) . class ( "col-md-4" ) ; {
96
- a ( label )
97
- . onClick ( this . selectRow . bind ( this , id ) )
100
+ a ( label ) . onClick ( this . selectRow . bind ( this , id ) )
98
101
}
99
102
td ( ) . class ( "col-md-1" ) ; {
100
103
a ( ) . onClick ( this . deleteRow . bind ( this , id ) ) ; {
0 commit comments