-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRedux.js
More file actions
34 lines (28 loc) · 790 Bytes
/
Redux.js
File metadata and controls
34 lines (28 loc) · 790 Bytes
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
import {extractCallFromType} from './Type'
export const doNothing = (state) => {
if (state === 0) {
return 0;
}
if (!state) return null;
return state;
};
export const byApiActionForCalls = (CALLS) => (reducer) => (state={}, action) => {
const apiAction = extractCallFromType(action.type, CALLS);
if (!apiAction) {
return state;
}
if (state===null || state===undefined) {
state = {};
}
return {...state, [apiAction] : reducer(state[apiAction], action)};
};
export const store = (value) => () => value;
export const storeNull = store(null);
export const storeError = (state, action) => ({...state, error: action.payload});
export default {
doNothing,
store,
storeNull,
storeError,
byApiActionForCalls
}