Skip to content

Commit

Permalink
fix(utils): meta reducers conflicting with initial state
Browse files Browse the repository at this point in the history
Closes ngrx#247
  • Loading branch information
Reko Jokelainen committed Aug 8, 2017
1 parent 84390a1 commit 9674b72
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions modules/store/spec/modules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,39 @@ describe(`Store Modules`, () => {
});
});

describe(`: With initial state`, () => {
const initialState: RootState = { fruit: 'banana' };
const reducerMap: ActionReducerMap<RootState> = { fruit: rootFruitReducer };
const noopMetaReducer = (r: Function) => (state: any, action: any) => {
return r(state, action);
};

const testWithMetaReducers = (metaReducers: any[]) => () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot(reducerMap, { initialState, metaReducers }),
],
});
store = TestBed.get(Store);
});
it('should have initial state', () => {
store.take(1).subscribe((s: any) => {
expect(s).toEqual(initialState);
});
});
};

describe(
'should add initial state with no meta reducers',
testWithMetaReducers([])
);
describe(
'should add initial state with a simple no-op meta reducer',
testWithMetaReducers([noopMetaReducer])
);
});

describe(`: Nested`, () => {
@NgModule({
imports: [StoreModule.forFeature('a', featureAReducer)],
Expand Down
2 changes: 1 addition & 1 deletion modules/store/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function createReducerFactory(
metaReducers?: ActionReducer<any, any>[]
): ActionReducerFactory<any, any> {
if (Array.isArray(metaReducers) && metaReducers.length > 0) {
return compose.apply(null, [...metaReducers, reducerFactory]);
return compose(...metaReducers)(reducerFactory) as any;
}

return reducerFactory;
Expand Down

0 comments on commit 9674b72

Please sign in to comment.