ampache_react/app/utils/reducers.js
Phyks (Lucas Verney) fffe9c4cd3 Major code review
Major code review, cleaning the code and adding a lot of comments. Also
implements a separate store to keep entities with a reference count and
garbage collection. This closes #15.

Known issues at the moment are:
* Webplayer is no longer working, it has to be refactored.
* AlbumPage is to be implemented.
2016-08-10 21:40:25 +02:00

23 lines
524 B
JavaScript

/**
* 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.
*/
export function createReducer(initialState, reducerMap) {
return (state = initialState, action) => {
const reducer = reducerMap[action.type];
return reducer
? reducer(state, action.payload)
: state;
};
}