UNPKG

@wordpress/data

Version:
21 lines (20 loc) 652 B
// packages/data/src/redux-store/combine-reducers.js 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; }; } export { combineReducers }; //# sourceMappingURL=combine-reducers.js.map