Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Store): dispatch one update action when multiple features are added or removed #1240

Merged
merged 1 commit into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 12 additions & 26 deletions modules/store/spec/store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,15 @@ describe('ngRx Store', () => {
store.addReducer(key, counterReducer);
expect(reducerManagerDispatcherSpy).toHaveBeenCalledWith({
type: UPDATE,
feature: key,
features: [key],
});
});

it('should dispatch an update reducers action when a reducer is removed', () => {
store.removeReducer(key);
expect(reducerManagerDispatcherSpy).toHaveBeenCalledWith({
type: UPDATE,
feature: key,
features: [key],
});
});
});
Expand Down Expand Up @@ -373,11 +373,11 @@ describe('ngRx Store', () => {

expect(reducerManagerDispatcherSpy).toHaveBeenCalledWith({
type: UPDATE,
feature: 'feature1',
features: ['feature1'],
});
});

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

expect(reducerManagerDispatcherSpy).toHaveBeenCalledTimes(2);

// get the first argument for the first call
expect(reducerManagerDispatcherSpy.calls.argsFor(0)[0]).toEqual({
type: UPDATE,
feature: 'feature1',
});

// get the first argument for the second call
expect(reducerManagerDispatcherSpy.calls.argsFor(1)[0]).toEqual({
expect(reducerManagerDispatcherSpy).toHaveBeenCalledTimes(1);
expect(reducerManagerDispatcherSpy).toHaveBeenCalledWith({
type: UPDATE,
feature: 'feature2',
features: ['feature1', 'feature2'],
});
});

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

expect(reducerManagerDispatcherSpy).toHaveBeenCalledWith({
type: UPDATE,
feature: 'feature1',
features: ['feature1'],
});
});

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

// get the first argument for the first call
expect(reducerManagerDispatcherSpy.calls.argsFor(0)[0]).toEqual({
type: UPDATE,
feature: 'feature1',
});

// get the first argument for the second call
expect(reducerManagerDispatcherSpy.calls.argsFor(1)[0]).toEqual({
expect(reducerManagerDispatcherSpy).toHaveBeenCalledTimes(1);
expect(reducerManagerDispatcherSpy).toHaveBeenCalledWith({
type: UPDATE,
feature: 'feature2',
features: ['feature1', 'feature2'],
});
});

Expand Down
9 changes: 3 additions & 6 deletions modules/store/src/reducer_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,9 @@ export class ReducerManager extends BehaviorSubject<ActionReducer<any, any>>

private updateReducers(featureKeys: string[]) {
this.next(this.reducerFactory(this.reducers, this.initialState));

featureKeys.forEach(feature => {
this.dispatcher.next(<Action>{
type: UPDATE,
feature,
});
this.dispatcher.next(<Action>{
type: UPDATE,
features: featureKeys,
});
}

Expand Down