33const assert = require ( "assert" ) ;
44import { Store , Payload } from "almin" ;
55import { ReduceState } from "./ReduceState" ;
6- export class ReduceStore extends Store {
7- state : ReduceState | null ;
6+ export class ReduceStore < T extends ReduceState > extends Store {
7+ state : T | null ;
88
99 constructor ( ) {
1010 super ( ) ;
11- /**
12- * @type {ReduceState }
13- **/
1411 this . state = null ;
1512 // Automatically handling onDispatch
1613 this . onDispatch ( this . _onDispatch . bind ( this ) ) ;
@@ -21,7 +18,7 @@ export class ReduceStore extends Store {
2118 * If `newState` is the same with `tis.state`, don't set.
2219 * @param {ReduceState } newState
2320 */
24- setState ( newState : ReduceState ) : void {
21+ setState ( newState : T ) : void {
2522 if ( process . env . NODE_ENV !== "production" ) {
2623 assert ( this . state !== null , "this.state is null, should be set to this.state in constructor." ) ;
2724 assert ( newState instanceof this . state ! . constructor , `newState should be instanceof exist this.state.constructor.
@@ -46,6 +43,6 @@ this.state.constructor: ${this.state!.constructor}
4643 assert ( this . state !== null , "this.state is null, should be set to this.state in constructor." ) ;
4744 assert ( payload !== undefined , `payload is undefined: ${ payload } ` ) ;
4845 }
49- this . setState ( this . state ! . reduce ( payload ) ) ;
46+ this . setState ( this . state ! . reduce < T > ( payload ) ) ;
5047 }
5148}
0 commit comments