@@ -59,7 +59,7 @@ const nouns = [
59
59
60
60
interface Data {
61
61
id : number ;
62
- label : WritableSignal < string > ;
62
+ label : string ;
63
63
}
64
64
65
65
@Component ( {
@@ -82,11 +82,9 @@ export class AppComponent {
82
82
for ( let i = 0 ; i < count ; i ++ ) {
83
83
data [ i ] = {
84
84
id : this . id ++ ,
85
- label : signal < string > (
86
- `${ adjectives [ this . #random( adjectives . length ) ] } ${
87
- colours [ this . #random( colours . length ) ]
88
- } ${ nouns [ this . #random( nouns . length ) ] } `,
89
- ) ,
85
+ label : `${ adjectives [ this . #random( adjectives . length ) ] } ${
86
+ colours [ this . #random( colours . length ) ]
87
+ } ${ nouns [ this . #random( nouns . length ) ] } `,
90
88
} ;
91
89
}
92
90
return data ;
@@ -103,13 +101,17 @@ export class AppComponent {
103
101
}
104
102
105
103
add ( ) {
106
- this . data . update ( data => [ ...data , ...this . buildData ( 1000 ) ] ) ;
104
+ this . data . update ( ( data ) => [ ...data , ...this . buildData ( 1000 ) ] ) ;
107
105
}
108
106
109
107
update ( ) {
110
- for ( let i = 0 , d = this . data ( ) , len = d . length ; i < len ; i += 10 ) {
111
- d [ i ] . label . update ( ( l ) => l + " !!!" ) ;
112
- }
108
+ this . data . update ( ( data ) => {
109
+ for ( let i = 0 ; i < data . length ; i += 10 ) {
110
+ const item = data [ i ] ;
111
+ data [ i ] = { ...item , label : item . label + " !!!" } ;
112
+ }
113
+ return data ;
114
+ } ) ;
113
115
}
114
116
115
117
clear ( ) {
@@ -132,9 +134,9 @@ export class AppComponent {
132
134
}
133
135
134
136
delete ( id : number ) {
135
- this . data . update ( d => {
136
- const idx = d . findIndex ( d => d . id === id ) ;
137
+ this . data . update ( ( d ) => {
138
+ const idx = d . findIndex ( ( d ) => d . id === id ) ;
137
139
return [ ...d . slice ( 0 , idx ) , ...d . slice ( idx + 1 ) ] ;
138
- } )
140
+ } ) ;
139
141
}
140
142
}
0 commit comments