@@ -8,48 +8,42 @@ const rows = State([]);
8
8
const selection = State ( ) ;
9
9
10
10
const create = ( ( ID , $ ) => count => [ ...Array ( count ) ] . map ( ( ) =>
11
- Row ( ++ ID , `${ $ ( adjectives ) } ${ $ ( colours ) } ${ $ ( nouns ) } ` )
11
+ Row ( ++ ID , State ( `${ $ ( adjectives ) } ${ $ ( colours ) } ${ $ ( nouns ) } ` ) )
12
12
) ) ( 0 , $ => $ [ Math . round ( Math . random ( ) * 1000 ) % $ . length ] ) ;
13
13
14
- const select = function ( ) { selection ( this . row . ID ) ; } ;
14
+ const select = function ( ) { selection ( this . ID ) ; } ;
15
15
16
- const remove = function ( ) {
17
- const data = new Set ( rows ( ) ) ;
18
- data . delete ( this . row ) && rows ( [ ...data ] ) ;
19
- } ;
16
+ const remove = ( filter => function ( ) {
17
+ rows ( rows ( ) . filter ( filter , this . ID ) ) ;
18
+ } ) ( function ( row ) { return row ?. ID !== this ; } ) ;
20
19
21
- const Row = ( ID , label ) => {
22
- const danger = State . track ( selection , ID ) ;
23
- const row = { is : 'tr' , class : { danger} , ID , label : State ( label ) } ;
24
- row . content = [
20
+ const Row = ( selected => ( ID , text ) =>
21
+ ( { is : 'tr' , content : [
25
22
{ is : 'td' , class : 'col-md-1' , content : ID } ,
26
23
{ is : 'td' , class : 'col-md-4' , content :
27
- { is : 'a' , action : select , row , content : row . label } } ,
24
+ { is : 'a' , action : select , content : text } } ,
28
25
{ is : 'td' , class : 'col-md-1' , content :
29
- { is : 'a' , action : remove , row , content : Icon ( ) } } ,
26
+ { is : 'a' , action : remove , content : Icon ( '' ) } } ,
30
27
{ is : 'td' , class : 'col-md-6' }
31
- ] ;
32
- return row ;
33
- } ;
28
+ ] , class : State . track ( selection , ID , selected ) , ID , text} )
29
+ ) ( on => on && 'danger' ) ;
34
30
35
- const Icon = ( type = '' ) =>
31
+ const Icon = name =>
36
32
( { is : 'span' , attrs : { 'aria-hidden' : 'true' } ,
37
- class : `glyphicon glyphicon-remove ${ type } ` } ) ;
33
+ class : `glyphicon glyphicon-remove ${ name } ` } ) ;
38
34
39
35
const actions = [
40
36
[ 'Create 1,000 rows' , 'run' , ( ) => rows ( create ( 1000 ) ) ] ,
41
37
[ 'Create 10,000 rows' , 'runlots' , ( ) => rows ( create ( 10000 ) ) ] ,
42
38
[ 'Append 1,000 rows' , 'add' , ( ) => rows ( [ ...rows ( ) , ...create ( 1000 ) ] ) ] ,
43
39
[ 'Clear' , 'clear' , ( ) => rows ( [ ] ) ] ,
44
40
[ 'Update every 10th row' , 'update' , ( ) => {
45
- const data = rows ( ) ;
46
- for ( let i = 0 , row ; i < data . length ; i += 10 )
47
- ( row = data [ i ] ) ?. label ( row . label ( ) + ' !!!' ) ;
41
+ for ( let i = 0 , all = rows ( ) , row ; i < all . length ; i += 10 )
42
+ ( row = all [ i ] ) ?. text ( `${ row . text ( ) } !!!` ) ;
48
43
} ] ,
49
44
[ 'Swap Rows' , 'swaprows' , ( ) => {
50
- const data = rows ( ) ;
51
- [ data [ 1 ] , data [ 998 ] ] = [ data [ 998 ] , data [ 1 ] ] ;
52
- rows ( [ ...data ] ) ;
45
+ const all = rows ( ) ;
46
+ [ all [ 1 ] , all [ 998 ] ] = [ all [ 998 ] , all [ 1 ] ] , rows ( [ ...all ] ) ;
53
47
} ] ] . map ( ( [ content , id , click ] ) =>
54
48
( { class : 'col-sm-6 smallpad' , content :
55
49
{ is : 'button' , id, class : 'btn btn-primary btn-block' ,
0 commit comments