@@ -7,7 +7,7 @@ import { Observable } from 'rxjs';
7
7
import { map } from 'rxjs/operators' ;
8
8
9
9
import { CountSubState } from './count-sub.state' ;
10
- import { ParentCountModel } from './count.model' ;
10
+ import { CountModel , ParentCountModel } from './count.model' ;
11
11
12
12
const COUNT_TOKEN : StateToken < ParentCountModel > = new StateToken < ParentCountModel > ( 'count' ) ;
13
13
@@ -19,28 +19,41 @@ const COUNT_TOKEN: StateToken<ParentCountModel> = new StateToken<ParentCountMode
19
19
} )
20
20
@Injectable ( )
21
21
export class CountState extends NgxsDataRepository < ParentCountModel > {
22
- public readonly values$ : Observable < ParentCountModel > = this . state$ . pipe ( map ( ( state ) => state . countSub ! ) ) ;
22
+ public readonly values$ : Observable < ParentCountModel > = this . state$ . pipe (
23
+ map ( ( state : Immutable < ParentCountModel > ) : CountModel => state . countSub ! )
24
+ ) ;
23
25
24
26
@action ( )
25
27
public increment ( ) : void {
26
- this . ctx . setState ( ( state : Immutable < ParentCountModel > ) => ( { ...state , val : state . val + 1 } ) ) ;
28
+ this . ctx . setState (
29
+ ( state : Immutable < ParentCountModel > ) : Immutable < ParentCountModel > => ( { ...state , val : state . val + 1 } )
30
+ ) ;
27
31
}
28
32
29
33
@action ( )
30
34
public countSubIncrement ( ) : void {
31
- this . ctx . setState ( ( state ) => ( {
32
- ...state ,
33
- countSub : { val : state . countSub ! . val + 1 }
34
- } ) ) ;
35
+ this . ctx . setState (
36
+ ( state : Immutable < ParentCountModel > ) : Immutable < ParentCountModel > => ( {
37
+ ...state ,
38
+ countSub : { val : state . countSub ! . val + 1 }
39
+ } )
40
+ ) ;
35
41
}
36
42
37
43
@action ( )
38
44
public decrement ( ) : void {
39
- this . setState ( ( state ) => ( { ...state , val : state . val - 1 } ) ) ;
45
+ this . setState (
46
+ ( state : Immutable < ParentCountModel > ) : Immutable < ParentCountModel > => ( { ...state , val : state . val - 1 } )
47
+ ) ;
40
48
}
41
49
42
50
@action ( { async : true , debounce : 300 } )
43
51
public setValueFromInput ( val : string | number ) : void {
44
- this . ctx . setState ( ( state ) => ( { ...state , val : parseFloat ( val as string ) || 0 } ) ) ;
52
+ this . ctx . setState (
53
+ ( state : Immutable < ParentCountModel > ) : Immutable < ParentCountModel > => ( {
54
+ ...state ,
55
+ val : parseFloat ( val as string ) || 0
56
+ } )
57
+ ) ;
45
58
}
46
59
}
0 commit comments