File tree 5 files changed +10
-10
lines changed
5 files changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,10 @@ export class Model<C extends ModelConfig> {
113
113
}
114
114
115
115
return ( ) : void => {
116
+ if ( this . options . autoReset ) {
117
+ this . model . state = this . initialState
118
+ }
119
+
116
120
// unsubscribe when component unmount
117
121
this . container . unsubscribe ( 'state' , subscriberRef . current as StateSubscriber < C [ 'state' ] > )
118
122
this . container . unsubscribe ( 'effect' , dispatcher )
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ type StoreModels<C extends Configs> = {
12
12
export class Store < C extends Configs > {
13
13
private models : StoreModels < C >
14
14
15
- constructor ( configs : C , options : StoreOptions < C > ) {
15
+ constructor ( configs : C , options : Required < StoreOptions < C > > ) {
16
16
this . models = this . initModels ( configs , options )
17
17
}
18
18
@@ -66,7 +66,7 @@ export class Store<C extends Configs> {
66
66
}
67
67
}
68
68
69
- private initModels ( configs : C , options : StoreOptions < C > ) : StoreModels < C > {
69
+ private initModels ( configs : C , options : Required < StoreOptions < C > > ) : StoreModels < C > {
70
70
const { name : storeName , autoReset, devTools } = options
71
71
const rootModel = Object . create ( null )
72
72
const modelNames = Object . keys ( configs )
Original file line number Diff line number Diff line change @@ -147,9 +147,9 @@ export interface ModelContextProps {
147
147
export type StoreProvider = React . FC < React . PropsWithChildren < any > >
148
148
149
149
export interface StoreOptions < C extends Configs > {
150
- name : string
151
- autoReset : boolean | UnionToTuple < keyof C >
152
- devTools : boolean | UnionToTuple < keyof C >
150
+ name ? : string
151
+ autoReset ? : boolean | UnionToTuple < keyof C >
152
+ devTools ? : boolean | UnionToTuple < keyof C >
153
153
}
154
154
155
155
export type HOC < InjectProps = any > = < P > (
Original file line number Diff line number Diff line change 1
1
import { Noop } from '../types'
2
2
3
+ /* istanbul-ignore-next */
3
4
function isTypeof ( target : any , type : string ) : boolean {
4
5
if ( ! type ) {
5
6
return false
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments