summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/createReducer.js
blob: 4af63739c15442d4248c5566341c67e0618fdc65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

/**
 * Helper to create a reducer that extend the store.
 *
 * @param  {String} property
 * @param  {Function(state, action): state} reduce
 * @return {Function(state, action): state}
 */
function createReducer(name, reduce) {
    return function(state, action) {
        const value = state[name];
        state[name] = reduce(value, action);
        return state;
    };
}

module.exports = createReducer;