1
- import { NgModule , Inject , ModuleWithProviders , OnDestroy } from '@angular/core' ;
2
- import { Action , ActionReducerMap , ActionReducerFactory , StoreFeature } from './models' ;
1
+ import { NgModule , Inject , ModuleWithProviders , OnDestroy , InjectionToken } from '@angular/core' ;
2
+ import { Action , ActionReducer , ActionReducerMap , ActionReducerFactory , StoreFeature } from './models' ;
3
3
import { combineReducers } from './utils' ;
4
4
import { INITIAL_STATE , INITIAL_REDUCERS , REDUCER_FACTORY , STORE_FEATURES } from './tokens' ;
5
5
import { ACTIONS_SUBJECT_PROVIDERS } from './actions_subject' ;
@@ -10,12 +10,12 @@ import { STORE_PROVIDERS } from './store';
10
10
11
11
12
12
13
- @NgModule ( { } )
13
+ @NgModule ( { } )
14
14
export class StoreRootModule {
15
15
16
16
}
17
17
18
- @NgModule ( { } )
18
+ @NgModule ( { } )
19
19
export class StoreFeatureModule implements OnDestroy {
20
20
constructor (
21
21
@Inject ( STORE_FEATURES ) private features : StoreFeature < any , any > [ ] ,
@@ -31,15 +31,15 @@ export class StoreFeatureModule implements OnDestroy {
31
31
32
32
export type StoreConfig < T , V extends Action = Action > = { initialState ?: T , reducerFactory ?: ActionReducerFactory < T , V > } ;
33
33
34
- @NgModule ( { } )
34
+ @NgModule ( { } )
35
35
export class StoreModule {
36
- static forRoot < T , V extends Action = Action > ( reducers : ActionReducerMap < T , V > , config ?: StoreConfig < T , V > ) : ModuleWithProviders ;
37
- static forRoot ( reducers : ActionReducerMap < any , any > , config : StoreConfig < any , any > = { } ) : ModuleWithProviders {
36
+ static forRoot < T , V extends Action = Action > ( reducers : ActionReducerMap < T , V > | InjectionToken < ActionReducerMap < T , V > > , config ?: StoreConfig < T , V > ) : ModuleWithProviders ;
37
+ static forRoot ( reducers : ActionReducerMap < any , any > | InjectionToken < ActionReducerMap < any , any > > , config : StoreConfig < any , any > = { } ) : ModuleWithProviders {
38
38
return {
39
39
ngModule : StoreRootModule ,
40
40
providers : [
41
41
{ provide : INITIAL_STATE , useValue : config . initialState } ,
42
- { provide : INITIAL_REDUCERS , useValue : reducers } ,
42
+ reducers instanceof InjectionToken ? { provide : INITIAL_REDUCERS , useExisting : reducers } : { provide : INITIAL_REDUCERS , useValue : reducers } ,
43
43
{ provide : REDUCER_FACTORY , useValue : config . reducerFactory ? config . reducerFactory : combineReducers } ,
44
44
ACTIONS_SUBJECT_PROVIDERS ,
45
45
REDUCER_MANAGER_PROVIDERS ,
@@ -51,7 +51,8 @@ export class StoreModule {
51
51
}
52
52
53
53
static forFeature < T , V extends Action = Action > ( featureName : string , reducers : ActionReducerMap < T , V > , config ?: StoreConfig < T , V > ) : ModuleWithProviders ;
54
- static forFeature ( featureName : string , reducers : ActionReducerMap < any , any > , config : StoreConfig < any , any > = { } ) : ModuleWithProviders {
54
+ static forFeature < T , V extends Action = Action > ( featureName : string , reducer : ActionReducer < T , V > , config ?: StoreConfig < T , V > ) : ModuleWithProviders ;
55
+ static forFeature ( featureName : string , reducers : ActionReducerMap < any , any > | ActionReducer < any , any > , config : StoreConfig < any , any > = { } ) : ModuleWithProviders {
55
56
return {
56
57
ngModule : StoreFeatureModule ,
57
58
providers : [
0 commit comments