File tree Expand file tree Collapse file tree 3 files changed +13
-13
lines changed
frameworks/keyed/preact-kr-observable/src Expand file tree Collapse file tree 3 files changed +13
-13
lines changed Original file line number Diff line number Diff line change 1
- import { render , h } from "preact" ;
1
+ import { render } from "preact" ;
2
2
import { observer } from 'kr-observable/preact' ;
3
3
import { Row } from './Row' ;
4
4
import { rowsStore } from './RowsStore' ;
5
- import { Fragment } from "preact" ;
6
5
7
6
const Button = ( { children, id, onClick } ) => {
8
7
return (
@@ -83,7 +82,5 @@ function Main() {
83
82
) ;
84
83
}
85
84
86
- if ( typeof window !== "undefined" ) {
87
- render ( < Main /> , document . getElementById ( 'main' ) ) ;
88
- }
85
+ render ( < Main /> , document . getElementById ( 'main' ) ) ;
89
86
Original file line number Diff line number Diff line change @@ -6,10 +6,10 @@ export const Row = observer(function row({ data }) {
6
6
< tr className = { data . selected ? 'danger' : '' } >
7
7
< td className = "col-md-1" > { data . id } </ td >
8
8
< td className = "col-md-4" >
9
- < a id = { data . id } onClick = { rowsStore . select } > { data . label } </ a >
9
+ < a id = { data . id } onClick = { ( ) => rowsStore . select ( data . id ) } > { data . label } </ a >
10
10
</ td >
11
11
< td className = "col-md-1" >
12
- < a onClick = { rowsStore . delete } >
12
+ < a onClick = { ( ) => rowsStore . delete ( data . id ) } >
13
13
< span
14
14
id = { data . id }
15
15
className = "glyphicon glyphicon-remove"
@@ -21,3 +21,4 @@ export const Row = observer(function row({ data }) {
21
21
</ tr >
22
22
) ;
23
23
} ) ;
24
+
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ export class RowsStore extends Observable {
5
5
static shallow = new Set ( [ 'rows' ] )
6
6
rows = [ ] ;
7
7
8
- delete ( e ) {
9
- const rowIndexToDelete = this . rows . findIndex ( ( row ) => row . id === + e . target . id ) ;
8
+ delete ( id ) {
9
+ const rowIndexToDelete = this . rows . findIndex ( row => row . id === id ) ;
10
10
this . rows . splice ( rowIndexToDelete , 1 ) ;
11
11
} ;
12
12
@@ -19,13 +19,14 @@ export class RowsStore extends Observable {
19
19
} ;
20
20
21
21
update ( ) {
22
- for ( let i = 0 ; i < this . rows . length ; i += 10 ) {
22
+ const length = this . rows . length ;
23
+ for ( let i = 0 ; i < length ; i += 10 ) {
23
24
this . rows [ i ] . label += ' !!!' ;
24
25
}
25
26
} ;
26
27
27
- select ( e ) {
28
- this . rows . forEach ( row => row . selected = row . id === + e . target . id )
28
+ select ( id ) {
29
+ this . rows . forEach ( row => row . selected = row . id === id )
29
30
} ;
30
31
31
32
runLots ( ) {
@@ -47,4 +48,5 @@ export class RowsStore extends Observable {
47
48
}
48
49
49
50
50
- export const rowsStore = new RowsStore ( )
51
+
52
+ export const rowsStore = new RowsStore ( )
You can’t perform that action at this time.
0 commit comments