1
- import { computed } from 'knockout' ;
2
-
3
- const Button = ( { id, text, fn} ) =>
4
- < div class = 'col-sm-6 smallpad' >
5
- < button id = { id } class = 'btn btn-primary btn-block' type = 'button' onClick = { fn } > { text } </ button >
6
- </ div >
7
-
8
- const selectRow = ( selected , rows ) => {
9
- let tr ;
10
- const cached = computed ( rows ) ;
11
- computed ( ( ) => {
12
- const s = selected ( ) ;
13
- if ( tr ) tr . className = '' ;
14
- if ( tr = s && cached ( ) . find ( tr => tr . model === s ) ) tr . className = 'danger' ;
15
- } ) ;
16
- return cached ;
17
- }
18
-
19
- export default function ( { data, selected, run, runLots, add, update, clear, swapRows, remove, select} ) {
20
- return < div class = 'container' >
21
- < div class = 'jumbotron' > < div class = 'row' >
22
- < div class = 'col-md-6' > < h1 > KnockoutJSX-keyed</ h1 > </ div >
23
- < div class = 'col-md-6' > < div class = 'row' >
24
- < Button id = 'run' text = 'Create 1,000 rows' fn = { run } />
25
- < Button id = 'runlots' text = 'Create 10,000 rows' fn = { runLots } />
26
- < Button id = 'add' text = 'Append 1,000 rows' fn = { add } />
27
- < Button id = 'update' text = 'Update every 10th row' fn = { update } />
28
- < Button id = 'clear' text = 'Clear' fn = { clear } />
29
- < Button id = 'swaprows' text = 'Swap Rows' fn = { swapRows } />
30
- </ div > </ div >
31
- </ div > </ div >
32
- < table class = 'table table-hover table-striped test-data' > < tbody > {
33
- selectRow ( selected , data . memoMap ( row =>
34
- < tr model = { row . id } >
35
- < td class = 'col-md-1' textContent = { row . id } />
36
- < td class = 'col-md-4' > < a onClick = { select } > { row . label } </ a > </ td >
37
- < td class = 'col-md-1' > < a onClick = { remove } > < span class = 'glyphicon glyphicon-remove' aria-hidden = 'true' /> </ a > </ td >
38
- < td class = 'col-md-6' />
39
- </ tr >
40
- ) )
41
- } </ tbody > </ table >
42
- < span class = 'preloadicon glyphicon glyphicon-remove' aria-hidden = "true" />
43
- </ div >
1
+ import { computed } from 'knockout' ;
2
+
3
+ const Button = ( { id, text, fn} ) =>
4
+ < div class = 'col-sm-6 smallpad' >
5
+ < button id = { id } class = 'btn btn-primary btn-block' type = 'button' onClick = { fn } > { text } </ button >
6
+ </ div >
7
+
8
+ const selectRow = ( selected , rows ) => {
9
+ let tr ;
10
+ const cached = computed ( rows ) ;
11
+ computed ( ( ) => {
12
+ const s = selected ( ) ;
13
+ if ( tr ) tr . className = '' ;
14
+ if ( tr = s && cached ( ) . find ( tr => tr . model === s ) ) tr . className = 'danger' ;
15
+ } ) ;
16
+ return cached ;
17
+ }
18
+
19
+ export default function ( { data, selected, run, runLots, add, update, clear, swapRows, remove, select} ) {
20
+ let rowId ;
21
+ const items = selectRow ( selected , data . memoMap ( row => (
22
+ rowId = row . id ,
23
+ < tr model = { rowId } >
24
+ < td class = 'col-md-1' textContent = { rowId } />
25
+ < td class = 'col-md-4' > < a onClick = { select } textContent = { row . label ( ) } /> </ td >
26
+ < td class = 'col-md-1' > < a onClick = { remove } > < span class = 'glyphicon glyphicon-remove' aria-hidden = 'true' /> </ a > </ td >
27
+ < td class = 'col-md-6' />
28
+ </ tr >
29
+ ) ) ) ;
30
+
31
+ return < div class = 'container' >
32
+ < div class = 'jumbotron' > < div class = 'row' >
33
+ < div class = 'col-md-6' > < h1 > KnockoutJSX-keyed</ h1 > </ div >
34
+ < div class = 'col-md-6' > < div class = 'row' >
35
+ < Button id = 'run' text = 'Create 1,000 rows' fn = { run } />
36
+ < Button id = 'runlots' text = 'Create 10,000 rows' fn = { runLots } />
37
+ < Button id = 'add' text = 'Append 1,000 rows' fn = { add } />
38
+ < Button id = 'update' text = 'Update every 10th row' fn = { update } />
39
+ < Button id = 'clear' text = 'Clear' fn = { clear } />
40
+ < Button id = 'swaprows' text = 'Swap Rows' fn = { swapRows } />
41
+ </ div > </ div >
42
+ </ div > </ div >
43
+ < table class = 'table table-hover table-striped test-data' > < tbody > {
44
+ items
45
+ } </ tbody > </ table >
46
+ < span class = 'preloadicon glyphicon glyphicon-remove' aria-hidden = "true" />
47
+ </ div >
44
48
}
0 commit comments