Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 6x 21x 21x 5x 5x 5x 16x | import produce from 'immer'; /** * Returns reducer for the module, given the module's mutations and initialState * * @param {Object<String, Function>} mutations - Mutations object for the module * @param {Object} initialState - initialState for the module * @returns {Function} reducer */ function getReducer(mutations, initialState) { return function _reducer(state = initialState, action) { const mutationMethod = mutations[action.type]; if (mutationMethod) { const nextState = produce(state, draftState => { mutationMethod(draftState, action); }); return nextState; } return state; }; } export default getReducer; |