diff --git a/modules/store/src/utils.ts b/modules/store/src/utils.ts index 7ded8a3810..2af2e75c8d 100644 --- a/modules/store/src/utils.ts +++ b/modules/store/src/utils.ts @@ -4,6 +4,7 @@ import { ActionReducerFactory, ActionReducerMap, MetaReducer, + InitialState, } from './models'; export function combineReducers( @@ -92,10 +93,17 @@ export function createReducerFactory( metaReducers?: MetaReducer[] ): ActionReducerFactory { if (Array.isArray(metaReducers) && metaReducers.length > 0) { - return compose.apply(null, [...metaReducers, reducerFactory]); + reducerFactory = compose.apply(null, [...metaReducers, reducerFactory]); } - return reducerFactory; + return (rm: ActionReducerMap, initialState?: InitialState) => { + const reducer = reducerFactory(rm, initialState); + + return (state: T | undefined, action: V) => { + state = state === undefined ? (initialState as T) : state; + return typeof reducer === 'function' ? reducer(state, action) : state; + }; + }; } export function createFeatureReducerFactory(