Skip to content

Commit

Permalink
Revert "fix(Store): Update usage of compose for reducer factory (#252)"
Browse files Browse the repository at this point in the history
This reverts commit 683013c.
  • Loading branch information
brandonroberts committed Aug 16, 2017
1 parent 71690fb commit eed6587
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 102 deletions.
33 changes: 0 additions & 33 deletions modules/store/spec/modules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,39 +119,6 @@ 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
66 changes: 1 addition & 65 deletions modules/store/spec/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { omit } from '../src/utils';
import {
ActionReducer,
ActionReducerMap,
combineReducers,
compose,
createReducerFactory,
MetaReducer
} from '@ngrx/store';
import { combineReducers, compose } from '@ngrx/store';

describe(`Store utils`, () => {
describe(`combineReducers()`, () => {
Expand Down Expand Up @@ -80,61 +73,4 @@ describe(`Store utils`, () => {
expect(id(1)).toBe(1);
});
});

describe(`createReducerFactory()`, () => {
const fruitReducer = (state: string = 'banana', action: any) =>
action.type === 'fruit' ? action.payload : state;
type FruitState = { fruit: string };
const reducerMap: ActionReducerMap<FruitState> = { fruit: fruitReducer };
const initialState: FruitState = { fruit: 'apple' };

const runWithExpectations = (
metaReducers: MetaReducer<FruitState>[],
initialState: any,
expectedState: any
) => () => {
let spiedFactory: jasmine.Spy;
let reducer: ActionReducer<FruitState>;
beforeEach(() => {
spiedFactory = jasmine
.createSpy('spied factory')
.and.callFake(combineReducers);
reducer = createReducerFactory(spiedFactory, metaReducers)(
reducerMap,
initialState
);
});
it(`should pass the reducers and initialState to the factory method`, () => {
expect(spiedFactory).toHaveBeenCalledWith(reducerMap, initialState);
});
it(`should return the expected initialState`, () => {
expect(reducer(undefined, { type: 'init' })).toEqual(expectedState);
});
};

describe(`without meta reducers`, () => {
const metaReducers: any[] = [];
describe(
`with initial state`,
runWithExpectations(metaReducers, initialState, initialState)
);
describe(
`without initial state`,
runWithExpectations(metaReducers, undefined, { fruit: 'banana' })
);
});

describe(`with meta reducers`, () => {
const noopMetaReducer = (r: any) => r;
const metaReducers: any[] = [noopMetaReducer];
describe(
`with initial state`,
runWithExpectations(metaReducers, initialState, initialState)
);
describe(
`without initial state`,
runWithExpectations(metaReducers, undefined, { fruit: 'banana' })
);
});
});
});
5 changes: 1 addition & 4 deletions modules/store/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ export function createReducerFactory<T, V extends Action = Action>(
metaReducers?: MetaReducer<T, V>[]
): ActionReducerFactory<T, V> {
if (Array.isArray(metaReducers) && metaReducers.length > 0) {
return compose(...metaReducers)(reducerFactory) as ActionReducerFactory<
any,
any
>;
return compose.apply(null, [...metaReducers, reducerFactory]);
}

return reducerFactory;
Expand Down

0 comments on commit eed6587

Please sign in to comment.