Skip to content

Commit

Permalink
fix(store): call metareducer with the user's config initial state
Browse files Browse the repository at this point in the history
  • Loading branch information
itay committed Jan 4, 2019
1 parent 6b73060 commit 541d8df
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions modules/store/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ActionReducerFactory,
ActionReducerMap,
MetaReducer,
InitialState,
} from './models';

export function combineReducers<T, V extends Action = Action>(
Expand Down Expand Up @@ -92,10 +93,17 @@ export function createReducerFactory<T, V extends Action = Action>(
metaReducers?: MetaReducer<T, V>[]
): ActionReducerFactory<T, V> {
if (Array.isArray(metaReducers) && metaReducers.length > 0) {
return compose.apply(null, [...metaReducers, reducerFactory]);
reducerFactory = compose.apply(null, [...metaReducers, reducerFactory]);
}

return reducerFactory;
return (rm: ActionReducerMap<T, V>, initialState?: InitialState<T>) => {
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<T, V extends Action = Action>(
Expand Down

0 comments on commit 541d8df

Please sign in to comment.