1 | const TYPE_ERROR = 'handleActions: Action Types should be not be undefined'; |
||
2 | const ACTION_ERROR = 'handleActions: action object should be not be undefined'; |
||
3 | |||
4 | export const handleActions = (map, initialState) => { |
||
0 ignored issues
–
show
|
|||
5 | Object.keys(map).forEach(key => { |
||
6 | if (key === 'undefined') { |
||
7 | throw new Error(TYPE_ERROR); |
||
8 | } |
||
9 | }); |
||
10 | |||
11 | return (state = initialState, action) => { |
||
12 | if (!action) { |
||
13 | throw new Error(ACTION_ERROR); |
||
14 | } |
||
15 | |||
16 | if (action.type === undefined) { |
||
17 | throw new Error(TYPE_ERROR); |
||
18 | } |
||
19 | |||
20 | const reducerSubFunction = map[action.type]; |
||
21 | |||
22 | if (typeof reducerSubFunction === 'function') { |
||
23 | return reducerSubFunction(state, action); |
||
24 | } |
||
25 | |||
26 | return state; |
||
27 | }; |
||
28 | }; |
||
29 | |||
30 | export default handleActions; |
||
31 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.