UNPKG

@wordpress/data

Version:
22 lines (21 loc) 691 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.combineReducers = combineReducers; function combineReducers(reducers) { const keys = Object.keys(reducers); return function combinedReducer(state = {}, action) { const nextState = {}; let hasChanged = false; for (const key of keys) { const reducer = reducers[key]; const prevStateForKey = state[key]; const nextStateForKey = reducer(prevStateForKey, action); nextState[key] = nextStateForKey; hasChanged = hasChanged || nextStateForKey !== prevStateForKey; } return hasChanged ? nextState : state; }; } //# sourceMappingURL=combine-reducers.js.map