Skip to content

Commit b1a64dd

Browse files
fix(store): remove store config from forFeature signature with slice (#3218)
Closes #3216 BREAKING CHANGES: The `StoreConfig` argument is removed from the `StoreModule.forFeature` signature with `FeatureSlice`. BEFORE: The `StoreModule.forFeature` signature with `FeatureSlice` has `StoreConfig` as the second input argument, but the configuration isn't registered if passed. AFTER: The `StoreModule.forFeature` signature with `FeatureSlice` no longer has `StoreConfig` as the second input argument.
1 parent 62334f9 commit b1a64dd

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

modules/store/spec/modules.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ describe(`Store Modules`, () => {
2626
);
2727

2828
// Trigger here is basically an action type used to trigger state update
29-
const createDummyReducer = <T>(def: T, trigger: string): ActionReducer<T> => (
30-
s = def,
31-
{ type, payload }: any
32-
) => (type === trigger ? payload : s);
29+
const createDummyReducer =
30+
<T>(def: T, trigger: string): ActionReducer<T> =>
31+
(s = def, { type, payload }: any) =>
32+
type === trigger ? payload : s;
3333
const rootFruitReducer = createDummyReducer('apple', 'fruit');
3434
const featureAReducer = createDummyReducer(5, 'a');
3535
const featureBListReducer = createDummyReducer([1, 2, 3], 'bList');
@@ -104,7 +104,7 @@ describe(`Store Modules`, () => {
104104
});
105105
});
106106

107-
it(`should should use config.reducerFactory`, (done) => {
107+
it(`should use config.reducerFactory`, (done) => {
108108
store.dispatch({ type: 'fruit', payload: 'banana' });
109109
store.dispatch({ type: 'a', payload: 42 });
110110

@@ -241,11 +241,12 @@ describe(`Store Modules`, () => {
241241
store = TestBed.inject(Store);
242242
});
243243

244-
it('should set up a feature state', () => {
244+
it('should set up a feature state', (done) => {
245245
store.pipe(take(1)).subscribe((state: State) => {
246246
expect(state).toEqual({
247247
a: 5,
248248
} as State);
249+
done();
249250
});
250251
});
251252
});

modules/store/spec/types/store_module.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { compilerOptions } from './utils';
44
describe('StoreModule', () => {
55
const expectSnippet = expecter(
66
(code) => `
7-
import {StoreModule,ActionReducerMap,Action} from '@ngrx/store';
7+
import { StoreModule, ActionReducerMap, Action, createReducer } from '@ngrx/store';
88
99
interface State {
1010
featureA: object;
@@ -69,5 +69,14 @@ describe('StoreModule', () => {
6969
/Type '{ notExisting: number; }' is not assignable to type 'InitialState<State>/
7070
);
7171
});
72+
73+
it('throws when store config is passed along with slice object', () => {
74+
expectSnippet(`
75+
StoreModule.forFeature(
76+
{ name: 'feature', reducer: createReducer(0) },
77+
{ initialState: 100, metaReducers: [metaReducer] }
78+
);
79+
`).toFail(/No overload matches this call/);
80+
});
7281
});
7382
});

modules/store/src/store_module.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,15 @@ export class StoreModule {
202202
config?: StoreConfig<T, V> | InjectionToken<StoreConfig<T, V>>
203203
): ModuleWithProviders<StoreFeatureModule>;
204204
static forFeature<T, V extends Action = Action>(
205-
slice: FeatureSlice<T, V>,
206-
config?: StoreConfig<T, V> | InjectionToken<StoreConfig<T, V>>
205+
slice: FeatureSlice<T, V>
207206
): ModuleWithProviders<StoreFeatureModule>;
208207
static forFeature(
209208
featureNameOrSlice: string | FeatureSlice<any, any>,
210-
reducersOrConfig?:
209+
reducers?:
211210
| ActionReducerMap<any, any>
212211
| InjectionToken<ActionReducerMap<any, any>>
213212
| ActionReducer<any, any>
214-
| InjectionToken<ActionReducer<any, any>>
215-
| StoreConfig<any, any>
216-
| InjectionToken<StoreConfig<any, any>>,
213+
| InjectionToken<ActionReducer<any, any>>,
217214
config: StoreConfig<any, any> | InjectionToken<StoreConfig<any, any>> = {}
218215
): ModuleWithProviders<StoreFeatureModule> {
219216
return {
@@ -257,15 +254,13 @@ export class StoreModule {
257254
useValue:
258255
featureNameOrSlice instanceof Object
259256
? featureNameOrSlice.reducer
260-
: reducersOrConfig,
257+
: reducers,
261258
},
262259
{
263260
provide: _FEATURE_REDUCERS_TOKEN,
264261
multi: true,
265262
useExisting:
266-
reducersOrConfig instanceof InjectionToken
267-
? reducersOrConfig
268-
: _FEATURE_REDUCERS,
263+
reducers instanceof InjectionToken ? reducers : _FEATURE_REDUCERS,
269264
},
270265
{
271266
provide: FEATURE_REDUCERS,

0 commit comments

Comments
 (0)