/**
 * Helper function for creating Redux reducers which allows us
 * to avoid using big switch-case statements and instead add
 * action listeners using object keys.
 *
 * @param {Object} initialState initial state for this reducer
 * @param {Object} handlers object where key is the action, and value is the reducer function for that action
 * @returns {Object} updated state
 */
export default function createReducer(initialState, handlers) {
    return (state = initialState, action) => {
        if (handlers[action.type]) {
            return handlers[action.type](state, action);
        }
        return state;
    };
}
