@@ -4,53 +4,42 @@ const adjectives = ["pretty", "large", "big", "small", "tall", "short", "long",
4
4
const colours = [ "red" , "yellow" , "blue" , "green" , "pink" , "brown" , "purple" , "brown" , "white" , "black" , "orange" ] ;
5
5
const nouns = [ "table" , "chair" , "house" , "bbq" , "desk" , "car" , "pony" , "cookie" , "sandwich" , "burger" , "pizza" , "mouse" , "keyboard" ] ;
6
6
7
- const rows = State ( [ ] ) ;
8
- const selection = State ( ) ;
7
+ const rows = State ( [ ] ) , selection = State ( ) ;
9
8
10
9
const create = ( ( ID , $ ) => count => [ ...Array ( count ) ] . map ( ( ) =>
11
10
Row ( ++ ID , State ( `${ $ ( adjectives ) } ${ $ ( colours ) } ${ $ ( nouns ) } ` ) )
12
11
) ) ( 0 , $ => $ [ Math . round ( Math . random ( ) * 1000 ) % $ . length ] ) ;
13
12
14
13
const select = function ( ) { selection ( this . ID ) ; } ;
15
14
16
- const remove = ( filter => function ( ) {
17
- rows ( rows ( ) . filter ( filter , this . ID ) ) ;
18
- } ) ( function ( row ) { return row ?. ID !== this ; } ) ;
15
+ const remove = function ( ) { rows ( rows ( ) . filter ( r => r ?. ID !== this . ID ) ) ; } ;
19
16
20
- const track = ( ref , value , resolve ) => {
21
- const tracker = State ( resolve ( State . peek ( ref ) === value ) ) ;
22
- return State . on ( ref , ( i , o ) =>
23
- i === value ? tracker ( resolve ( true ) ) :
24
- o === value && tracker ( resolve ( false ) ) ) , tracker ;
25
- } ;
17
+ State . on ( selection , ( i , o ) => rows ( ) . forEach ( ( { ID , class : $ } ) =>
18
+ ID === i ? $ ( 'danger' ) : ID === o && $ ( null ) ) ) ;
26
19
27
- const Row = ( selected => ( ID , text ) =>
28
- ( { is : 'tr' , content : [
29
- { is : 'td' , class : 'col-md-1' , content : ID } ,
30
- { is : 'td' , class : 'col-md-4' , content :
31
- { is : 'a' , action : select , content : text } } ,
32
- { is : 'td' , class : 'col-md-1' , content :
33
- { is : 'a' , action : remove , content : Icon ( '' ) } } ,
34
- { is : 'td' , class : 'col-md-6' }
35
- ] , class : track ( selection , ID , selected ) , ID , text} )
36
- ) ( on => on && 'danger' ) ;
20
+ const Row = ( ID , text ) => ( { is : 'tr' , content : [
21
+ { is : 'td' , class : 'col-md-1' , content : ID } ,
22
+ { is : 'td' , class : 'col-md-4' , content :
23
+ { is : 'a' , action : select , content : text } } ,
24
+ { is : 'td' , class : 'col-md-1' , content :
25
+ { is : 'a' , action : remove , content : { is : 'span' , attrs : icon } } } ,
26
+ { is : 'td' , class : 'col-md-6' }
27
+ ] , ID , text, class : State ( ) } ) ;
37
28
38
- const Icon = name =>
39
- ( { is : 'span' , attrs : { 'aria-hidden' : 'true' } ,
40
- class : `glyphicon glyphicon-remove ${ name } ` } ) ;
29
+ const icon = { class : 'glyphicon glyphicon-remove' , 'aria-hidden' : 'true' } ;
41
30
42
31
const actions = [
43
32
[ 'Create 1,000 rows' , 'run' , ( ) => rows ( create ( 1000 ) ) ] ,
44
33
[ 'Create 10,000 rows' , 'runlots' , ( ) => rows ( create ( 10000 ) ) ] ,
45
34
[ 'Append 1,000 rows' , 'add' , ( ) => rows ( [ ...rows ( ) , ...create ( 1000 ) ] ) ] ,
46
35
[ 'Update every 10th row' , 'update' , ( ) => {
47
- for ( let r = rows ( ) , i = 0 ; i < r . length ; i += 10 )
48
- r [ i ] ?. text ( ` ${ r [ i ] . text ( ) } !!!` ) ;
36
+ for ( let r = rows ( ) , t , i = 0 ; t = r [ i ] ?. text ; i += 10 )
37
+ t ( t ( ) + ' !!!' ) ;
49
38
} ] ,
50
39
[ 'Clear' , 'clear' , ( ) => rows ( [ ] ) ] ,
51
40
[ 'Swap Rows' , 'swaprows' , ( ) => {
52
- const r = rows ( ) ;
53
- [ r [ 1 ] , r [ 998 ] ] = [ r [ 998 ] , r [ 1 ] ] , rows ( [ ... r ] ) ;
41
+ const r = [ ... rows ( ) ] ;
42
+ r [ 998 ] && ( [ r [ 1 ] , r [ 998 ] ] = [ r [ 998 ] , r [ 1 ] ] , rows ( r ) ) ;
54
43
} ] ] . map ( ( [ content , id , click ] ) =>
55
44
( { class : 'col-sm-6 smallpad' , content :
56
45
{ is : 'button' , id, class : 'btn btn-primary btn-block' ,
@@ -64,10 +53,9 @@ insert({id: 'main', content:
64
53
{ is : 'h1' , content : document . title } } ,
65
54
{ class : 'col-md-6' , content : { class : 'row' , content : actions } }
66
55
] }
67
- } ,
56
+ } , { is : 'span' , attrs : icon , class : { preloadicon : true } } ,
68
57
{ is : 'table' , class : 'table table-hover table-striped test-data' ,
69
58
content : { is : 'tbody' , id : 'tbody' , content : rows } ,
70
- listen : { click : ( event , context ) => context ?. action ?. ( ) } } ,
71
- Icon ( 'preloadicon' )
59
+ listen : { click : ( e , context ) => context ?. action ?. ( ) } }
72
60
] }
73
61
} , document . body ) ;
0 commit comments