Skip to content

Commit 0b90f91

Browse files
timdeschryverbrandonroberts
authored andcommitted
feat(store): dispatch one update action when features are added or removed (#1240)
BREAKING CHANGE: BEFORE: ```ts {type: '@ngrx/store/update-reducers', feature: 'feature1'} {type: '@ngrx/store/update-reducers', feature: 'feature2'} ``` AFTER: ```ts {type: '@ngrx/store/update-reducers', features: ['feature1', 'feature2']} ```
1 parent b3fc5dd commit 0b90f91

File tree

2 files changed

+15
-32
lines changed

2 files changed

+15
-32
lines changed

modules/store/spec/store.spec.ts

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,15 @@ describe('ngRx Store', () => {
337337
store.addReducer(key, counterReducer);
338338
expect(reducerManagerDispatcherSpy).toHaveBeenCalledWith({
339339
type: UPDATE,
340-
feature: key,
340+
features: [key],
341341
});
342342
});
343343

344344
it('should dispatch an update reducers action when a reducer is removed', () => {
345345
store.removeReducer(key);
346346
expect(reducerManagerDispatcherSpy).toHaveBeenCalledWith({
347347
type: UPDATE,
348-
feature: key,
348+
features: [key],
349349
});
350350
});
351351
});
@@ -373,11 +373,11 @@ describe('ngRx Store', () => {
373373

374374
expect(reducerManagerDispatcherSpy).toHaveBeenCalledWith({
375375
type: UPDATE,
376-
feature: 'feature1',
376+
features: ['feature1'],
377377
});
378378
});
379379

380-
it('should dispatch an update reducers action for each feature that is added', () => {
380+
it('should dispatch an update reducers action when multiple features are added', () => {
381381
reducerManager.addFeatures([
382382
createFeature({
383383
key: 'feature1',
@@ -387,18 +387,10 @@ describe('ngRx Store', () => {
387387
}),
388388
]);
389389

390-
expect(reducerManagerDispatcherSpy).toHaveBeenCalledTimes(2);
391-
392-
// get the first argument for the first call
393-
expect(reducerManagerDispatcherSpy.calls.argsFor(0)[0]).toEqual({
394-
type: UPDATE,
395-
feature: 'feature1',
396-
});
397-
398-
// get the first argument for the second call
399-
expect(reducerManagerDispatcherSpy.calls.argsFor(1)[0]).toEqual({
390+
expect(reducerManagerDispatcherSpy).toHaveBeenCalledTimes(1);
391+
expect(reducerManagerDispatcherSpy).toHaveBeenCalledWith({
400392
type: UPDATE,
401-
feature: 'feature2',
393+
features: ['feature1', 'feature2'],
402394
});
403395
});
404396

@@ -411,11 +403,11 @@ describe('ngRx Store', () => {
411403

412404
expect(reducerManagerDispatcherSpy).toHaveBeenCalledWith({
413405
type: UPDATE,
414-
feature: 'feature1',
406+
features: ['feature1'],
415407
});
416408
});
417409

418-
it('should dispatch an update reducers action for each feature that is removed', () => {
410+
it('should dispatch an update reducers action when multiple features are removed', () => {
419411
reducerManager.removeFeatures([
420412
createFeature({
421413
key: 'feature1',
@@ -425,16 +417,10 @@ describe('ngRx Store', () => {
425417
}),
426418
]);
427419

428-
// get the first argument for the first call
429-
expect(reducerManagerDispatcherSpy.calls.argsFor(0)[0]).toEqual({
430-
type: UPDATE,
431-
feature: 'feature1',
432-
});
433-
434-
// get the first argument for the second call
435-
expect(reducerManagerDispatcherSpy.calls.argsFor(1)[0]).toEqual({
420+
expect(reducerManagerDispatcherSpy).toHaveBeenCalledTimes(1);
421+
expect(reducerManagerDispatcherSpy).toHaveBeenCalledWith({
436422
type: UPDATE,
437-
feature: 'feature2',
423+
features: ['feature1', 'feature2'],
438424
});
439425
});
440426

modules/store/src/reducer_manager.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,9 @@ export class ReducerManager extends BehaviorSubject<ActionReducer<any, any>>
9292

9393
private updateReducers(featureKeys: string[]) {
9494
this.next(this.reducerFactory(this.reducers, this.initialState));
95-
96-
featureKeys.forEach(feature => {
97-
this.dispatcher.next(<Action>{
98-
type: UPDATE,
99-
feature,
100-
});
95+
this.dispatcher.next(<Action>{
96+
type: UPDATE,
97+
features: featureKeys,
10198
});
10299
}
103100

0 commit comments

Comments
 (0)