1
1
import {
2
- type ObservableType ,
3
- observePrimitiveValue ,
2
+ type PrimitiveObservableType ,
3
+ useObservePrimitive ,
4
4
ProxiedArray ,
5
5
create ,
6
6
} from "@michijs/michijs" ;
7
7
8
8
interface Row {
9
- label : ObservableType < string > ;
9
+ label : PrimitiveObservableType < string > ;
10
10
id : number ;
11
- selected : ObservableType < string | null > ;
11
+ selected : PrimitiveObservableType < string | null > ;
12
12
}
13
13
const adjectives = [
14
- "pretty" ,
15
- "large" ,
16
- "big" ,
17
- "small" ,
18
- "tall" ,
19
- "short" ,
20
- "long" ,
21
- "handsome" ,
22
- "plain" ,
23
- "quaint" ,
24
- "clean" ,
25
- "elegant" ,
26
- "easy" ,
27
- "angry" ,
28
- "crazy" ,
29
- "helpful" ,
30
- "mushy" ,
31
- "odd" ,
32
- "unsightly" ,
33
- "adorable" ,
34
- "important" ,
35
- "inexpensive" ,
36
- "cheap" ,
37
- "expensive" ,
38
- "fancy" ,
39
- ] ,
14
+ "pretty" ,
15
+ "large" ,
16
+ "big" ,
17
+ "small" ,
18
+ "tall" ,
19
+ "short" ,
20
+ "long" ,
21
+ "handsome" ,
22
+ "plain" ,
23
+ "quaint" ,
24
+ "clean" ,
25
+ "elegant" ,
26
+ "easy" ,
27
+ "angry" ,
28
+ "crazy" ,
29
+ "helpful" ,
30
+ "mushy" ,
31
+ "odd" ,
32
+ "unsightly" ,
33
+ "adorable" ,
34
+ "important" ,
35
+ "inexpensive" ,
36
+ "cheap" ,
37
+ "expensive" ,
38
+ "fancy" ,
39
+ ] ,
40
40
colours = [
41
41
"red" ,
42
42
"yellow" ,
@@ -73,23 +73,21 @@ const adjectives = [
73
73
const data = new Array < Row > ( count ) ;
74
74
for ( let i = 0 ; i < count ; i ++ )
75
75
data [ i ] = {
76
- selected : observePrimitiveValue < string | null > ( null ) ,
76
+ selected : useObservePrimitive < string | null > ( null ) ,
77
77
id : nextId ++ ,
78
- label : observePrimitiveValue (
78
+ label : useObservePrimitive (
79
79
`${ adjectives [ _random ( adjectivesLength ) ] } ${ colours [ _random ( coloursLength ) ] } ${ nouns [ _random ( nounsLength ) ] } ` ,
80
80
) ,
81
81
} ;
82
82
return data ;
83
83
} ,
84
- rows = new ProxiedArray < Row > ( [ ] , undefined , true ) ,
85
- run = ( ) => rows . $replace ( buildData ( ) ) ,
86
- runLots = ( ) => rows . $replace ( buildData ( 10000 ) ) ,
84
+ rows = new ProxiedArray < Row > ( ) ,
85
+ run = ( ) => rows . $replace ( ... buildData ( ) ) ,
86
+ runLots = ( ) => rows . $replace ( ... buildData ( 10000 ) ) ,
87
87
add = ( ) => rows . push ( ...buildData ( ) ) ,
88
88
update = ( ) => {
89
- const array = rows . $value ,
90
- length = array . length ;
91
- for ( let i = 0 ; i < length ; i += 10 ) {
92
- const label = array [ i ] . label ;
89
+ for ( let i = 0 ; i < rows . length ; i += 10 ) {
90
+ const label = rows [ i ] . label ;
93
91
label ( `${ label ( ) } !!!` ) ;
94
92
}
95
93
} ,
@@ -99,8 +97,7 @@ const adjectives = [
99
97
if ( selectedItem ) selectedItem . selected ( null ) ;
100
98
selectedItem = row ;
101
99
} ,
102
- deleteItem = ( id : number ) =>
103
- rows . $remove ( rows . $value . findIndex ( ( x ) => x . id === id ) ) ,
100
+ deleteItem = ( id : number ) => rows . $remove ( rows . findIndex ( ( x ) => x . id === id ) ) ,
104
101
swapRows = ( ) => rows . $swap ( 1 , 998 ) ;
105
102
106
103
let nextId = 1 ,
0 commit comments