@@ -114,6 +114,14 @@ export interface RootStoreConfig<T, V extends Action = Action>
114
114
runtimeChecks ?: Partial < RuntimeChecks > ;
115
115
}
116
116
117
+ /**
118
+ * An object with the name and the reducer for the feature.
119
+ */
120
+ export interface FeatureSlice < T , V extends Action = Action > {
121
+ name : string ;
122
+ reducer : ActionReducer < T , V > ;
123
+ }
124
+
117
125
@NgModule ( { } )
118
126
export class StoreModule {
119
127
static forRoot < T , V extends Action = Action > (
@@ -192,15 +200,36 @@ export class StoreModule {
192
200
reducer : ActionReducer < T , V > | InjectionToken < ActionReducer < T , V > > ,
193
201
config ?: StoreConfig < T , V > | InjectionToken < StoreConfig < T , V > >
194
202
) : ModuleWithProviders < StoreFeatureModule > ;
203
+ static forFeature < T , V extends Action = Action > (
204
+ slice : FeatureSlice < T , V > ,
205
+ config ?: StoreConfig < T , V > | InjectionToken < StoreConfig < T , V > >
206
+ ) : ModuleWithProviders < StoreFeatureModule > ;
195
207
static forFeature (
196
- featureName : string ,
197
- reducers :
208
+ featureNameOrSlice : string | FeatureSlice < any , any > ,
209
+ reducersOrConfig ? :
198
210
| ActionReducerMap < any , any >
199
211
| InjectionToken < ActionReducerMap < any , any > >
200
212
| ActionReducer < any , any >
201
- | InjectionToken < ActionReducer < any , any > > ,
213
+ | InjectionToken < ActionReducer < any , any > >
214
+ | StoreConfig < any , any >
215
+ | InjectionToken < StoreConfig < any , any > > ,
202
216
config : StoreConfig < any , any > | InjectionToken < StoreConfig < any , any > > = { }
203
217
) : ModuleWithProviders < StoreFeatureModule > {
218
+ let featureName : string ;
219
+ let reducers :
220
+ | ActionReducerMap < any , any >
221
+ | InjectionToken < ActionReducerMap < any , any > >
222
+ | ActionReducer < any , any >
223
+ | InjectionToken < ActionReducer < any , any > > ;
224
+ if ( typeof featureNameOrSlice === 'string' ) {
225
+ featureName = featureNameOrSlice ;
226
+ reducers = reducersOrConfig as any ;
227
+ } else {
228
+ featureName = featureNameOrSlice . name ;
229
+ reducers = featureNameOrSlice . reducer ;
230
+ config = ( reducersOrConfig as any ) ?? { } ;
231
+ }
232
+
204
233
return {
205
234
ngModule : StoreFeatureModule ,
206
235
providers : [
0 commit comments