2016-08-10 21:36:11 +02:00
|
|
|
/**
|
|
|
|
* Collection of helper functions to deal with reducers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility function to create a reducer.
|
|
|
|
*
|
|
|
|
* @param initialState Initial state of the reducer.
|
|
|
|
* @param reducerMap Map between action types and reducing functions.
|
|
|
|
*
|
|
|
|
* @return A reducer.
|
|
|
|
*/
|
2016-07-07 23:23:18 +02:00
|
|
|
export function createReducer(initialState, reducerMap) {
|
|
|
|
return (state = initialState, action) => {
|
|
|
|
const reducer = reducerMap[action.type];
|
|
|
|
|
|
|
|
return reducer
|
|
|
|
? reducer(state, action.payload)
|
|
|
|
: state;
|
|
|
|
};
|
|
|
|
}
|