1
- import { State , root , memo } from 'solid-js' ;
2
- import { r , selectOn , delegateEvent } from 'solid-js/dom' ;
1
+ import { State , root , each } from 'solid-js' ;
2
+ import { r , selectWhen } from 'solid-js/dom' ;
3
3
4
4
function _random ( max ) {
5
5
return Math . round ( Math . random ( ) * 1000 ) % max ;
@@ -22,7 +22,7 @@ function buildData(count) {
22
22
}
23
23
24
24
function App ( ) {
25
- let rowId , selectClass , clickSelect , clickRemove , tbody ;
25
+ let rowId ;
26
26
const state = new State ( { data : [ ] , selected : null } ) ;
27
27
28
28
return < div class = 'container' >
@@ -49,33 +49,28 @@ function App() {
49
49
</ div >
50
50
</ div > </ div >
51
51
</ div > </ div >
52
- < table class = 'table table-hover table-striped test-data' > < tbody ref = { tbody } > {
53
- ( selectClass = selectOn ( ( ) => state . selected , ( el , selected ) => el . className = selected ? 'danger' : '' ) ,
54
- clickSelect = delegateEvent ( tbody , 'click' , onSelect ) ,
55
- clickRemove = delegateEvent ( tbody , 'click' , onRemove ) ,
56
- memo ( row =>
52
+ < table class = 'table table-hover table-striped test-data' > < tbody onClick = { clickRow } > {
53
+ selectWhen ( ( ) => state . selected , ( el , selected ) => el . className = selected ? 'danger' : '' )
54
+ ( each ( row =>
57
55
( rowId = row . sample ( 'id' ) ,
58
- < tr $selectClass = { rowId } >
56
+ < tr model = { ( ( rowId ) ) } >
59
57
< td class = 'col-md-1' textContent = { ( ( rowId ) ) } />
60
- < td class = 'col-md-4' > < a $clickSelect = { rowId } > { row . label } </ a > </ td >
61
- < td class = 'col-md-1' > < a $clickRemove = { rowId } > < span class = 'delete glyphicon glyphicon-remove' /> </ a > </ td >
58
+ < td class = 'col-md-4' > < a > { row . label } </ a > </ td >
59
+ < td class = 'col-md-1' > < a > < span class = 'delete glyphicon glyphicon-remove' /> </ a > </ td >
62
60
< td class = 'col-md-6' />
63
61
</ tr > )
64
62
) ( ( ) => state . data ) )
65
63
} </ tbody > </ table >
66
64
< span class = 'preloadicon glyphicon glyphicon-remove' aria-hidden = "true" />
67
65
</ div >
68
66
69
- function onRemove ( id , e ) {
67
+ function clickRow ( e , id ) {
70
68
e . stopPropagation ( ) ;
71
- state . set ( {
72
- data : state . data . filter ( row => row . id !== id )
73
- } ) ;
74
- }
75
-
76
- function onSelect ( id , e ) {
77
- e . stopPropagation ( ) ;
78
- state . set ( { selected : id } ) ;
69
+ if ( e . target . matches ( '.delete' ) ) {
70
+ state . set ( {
71
+ data : state . data . filter ( row => row . id !== id )
72
+ } ) ;
73
+ } else state . set ( { selected : id } )
79
74
}
80
75
81
76
function run ( e ) {
0 commit comments