@@ -3,9 +3,49 @@ import { htm } from "@ivi/tpl";
3
3
import { Entry , State , Action , ActionType } from "./types.js" ;
4
4
5
5
const random = ( max : number ) => Math . round ( Math . random ( ) * 1000 ) % max ;
6
- const A = [ "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 A = [
7
+ "pretty" ,
8
+ "large" ,
9
+ "big" ,
10
+ "small" ,
11
+ "tall" ,
12
+ "short" ,
13
+ "long" ,
14
+ "handsome" ,
15
+ "plain" ,
16
+ "quaint" ,
17
+ "clean" ,
18
+ "elegant" ,
19
+ "easy" ,
20
+ "angry" ,
21
+ "crazy" ,
22
+ "helpful" ,
23
+ "mushy" ,
24
+ "odd" ,
25
+ "unsightly" ,
26
+ "adorable" ,
27
+ "important" ,
28
+ "inexpensive" ,
29
+ "cheap" ,
30
+ "expensive" ,
31
+ "fancy" ,
32
+ ] ;
7
33
const C = [ "red" , "yellow" , "blue" , "green" , "pink" , "brown" , "purple" , "brown" , "white" , "black" , "orange" ] ;
8
- const N = [ "table" , "chair" , "house" , "bbq" , "desk" , "car" , "pony" , "cookie" , "sandwich" , "burger" , "pizza" , "mouse" , "keyboard" ] ;
34
+ const N = [
35
+ "table" ,
36
+ "chair" ,
37
+ "house" ,
38
+ "bbq" ,
39
+ "desk" ,
40
+ "car" ,
41
+ "pony" ,
42
+ "cookie" ,
43
+ "sandwich" ,
44
+ "burger" ,
45
+ "pizza" ,
46
+ "mouse" ,
47
+ "keyboard" ,
48
+ ] ;
9
49
10
50
let nextId = 1 ;
11
51
function buildData ( count : number ) : Entry [ ] {
@@ -64,15 +104,19 @@ interface RowProps {
64
104
}
65
105
66
106
const Row = component < RowProps > ( ( c ) => {
67
- const onSelect = ( ) => { dispatch ( c , { type : ActionType . Select , entry : getProps ( c ) . entry } ) ; } ;
68
- const onRemove = ( ) => { dispatch ( c , { type : ActionType . Remove , entry : getProps ( c ) . entry } ) ; } ;
107
+ const onSelect = ( ) => {
108
+ dispatch ( c , { type : ActionType . Select , entry : getProps ( c ) . entry } ) ;
109
+ } ;
110
+ const onRemove = ( ) => {
111
+ dispatch ( c , { type : ActionType . Remove , entry : getProps ( c ) . entry } ) ;
112
+ } ;
69
113
return ( { entry, selected } ) => htm `
70
114
tr${ selected === true ? "danger" : "" }
71
115
td.col-md-1 =${ entry . id }
72
116
td.col-md-4
73
- a @click=${ onSelect } =${ entry . label }
117
+ a.lbl @click=${ onSelect } =${ entry . label }
74
118
td.col-md-1
75
- a @click=${ onRemove } span.glyphicon.glyphicon-remove :aria-hidden='true'
119
+ a.remove @click=${ onRemove } span.remove .glyphicon.glyphicon-remove :aria-hidden='true'
76
120
td.col-md-6
77
121
` ;
78
122
} ) ;
@@ -86,14 +130,28 @@ const Button = (text: string, id: string, onClick: () => void) => /* preventClon
86
130
const App = component ( ( c ) => {
87
131
const [ _state , _dispatch ] = useReducer ( c , INITIAL_STATE , appStateReducer ) ;
88
132
89
- const onDispatch = ( ev : CustomEvent < Action > ) => { _dispatch ( ev . detail ) ; } ;
133
+ const onDispatch = ( ev : CustomEvent < Action > ) => {
134
+ _dispatch ( ev . detail ) ;
135
+ } ;
90
136
const buttons = [
91
- Button ( "Create 1,000 rows" , "run" , ( ) => { _dispatch ( { type : ActionType . Run } ) ; } ) ,
92
- Button ( "Create 10,000 rows" , "runlots" , ( ) => { _dispatch ( { type : ActionType . RunLots } ) ; } ) ,
93
- Button ( "Append 1,000 rows" , "add" , ( ) => { _dispatch ( { type : ActionType . Add } ) ; } ) ,
94
- Button ( "Update every 10th row" , "update" , ( ) => { _dispatch ( { type : ActionType . Update } ) ; } ) ,
95
- Button ( "Clear" , "clear" , ( ) => { _dispatch ( { type : ActionType . Clear } ) ; } ) ,
96
- Button ( "Swap Rows" , "swaprows" , ( ) => { _dispatch ( { type : ActionType . SwapRows } ) ; } ) ,
137
+ Button ( "Create 1,000 rows" , "run" , ( ) => {
138
+ _dispatch ( { type : ActionType . Run } ) ;
139
+ } ) ,
140
+ Button ( "Create 10,000 rows" , "runlots" , ( ) => {
141
+ _dispatch ( { type : ActionType . RunLots } ) ;
142
+ } ) ,
143
+ Button ( "Append 1,000 rows" , "add" , ( ) => {
144
+ _dispatch ( { type : ActionType . Add } ) ;
145
+ } ) ,
146
+ Button ( "Update every 10th row" , "update" , ( ) => {
147
+ _dispatch ( { type : ActionType . Update } ) ;
148
+ } ) ,
149
+ Button ( "Clear" , "clear" , ( ) => {
150
+ _dispatch ( { type : ActionType . Clear } ) ;
151
+ } ) ,
152
+ Button ( "Swap Rows" , "swaprows" , ( ) => {
153
+ _dispatch ( { type : ActionType . SwapRows } ) ;
154
+ } ) ,
97
155
] ;
98
156
99
157
return ( ) => {
@@ -106,16 +164,20 @@ const App = component((c) => {
106
164
div.col-md-6 div.row ${ buttons }
107
165
table.table.table-hover.table-striped.test-data
108
166
@dispatch=${ onDispatch }
109
- ${ data . length
110
- ? htm `tbody ${ List ( data , getEntryId , ( entry ) => Row ( { entry, selected : selected === entry . id } ) ) } `
111
- : htm `tbody` }
167
+ ${
168
+ data . length
169
+ ? htm `tbody ${ List ( data , getEntryId , ( entry ) => Row ( { entry, selected : selected === entry . id } ) ) } `
170
+ : htm `tbody`
171
+ }
112
172
span.preloadicon.glyphicon.glyphicon-remove :aria-hidden='true'
113
173
` ;
114
174
} ;
115
175
} ) ;
116
176
117
177
update (
118
178
// Defines a custom root node that disables batching for benchmark.
119
- defineRoot ( ( root ) => { dirtyCheck ( root ) ; } ) ( document . getElementById ( "main" ) ! ) ,
179
+ defineRoot ( ( root ) => {
180
+ dirtyCheck ( root ) ;
181
+ } ) ( document . getElementById ( "main" ) ! ) ,
120
182
App ( )
121
183
) ;
0 commit comments