-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
combineReducers.js
47 lines (35 loc) · 1.38 KB
/
combineReducers.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* eslint-disable lodash3/prefer-lodash-method */
import {
getUnexpectedInvocationParameterMessage,
validateNextState
} from './utilities';
export default (reducers: Object) => {
let reducerKeys;
reducerKeys = Object.keys(reducers);
return (inputState, action) => {
/* eslint-disable no-process-env */
if (process.env.NODE_ENV !== 'production') {
/* eslint-enable no-process-env */
let warningMessage;
warningMessage = getUnexpectedInvocationParameterMessage(inputState, reducers, action);
if (warningMessage) {
/* eslint-disable no-console */
console.error(warningMessage);
/* eslint-enable no-console */
}
}
return inputState
.withMutations((temporaryState) => {
reducerKeys.forEach((reducerName) => {
let currentDomainState,
nextDomainState,
reducer;
reducer = reducers[reducerName];
currentDomainState = temporaryState.get(reducerName);
nextDomainState = reducer(currentDomainState, action);
validateNextState(nextDomainState, reducerName, action);
temporaryState.set(reducerName, nextDomainState);
});
});
};
};