Total Complexity | 12 |
Complexity/F | 6 |
Lines of Code | 43 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | /* |
||
11 | export const stateGetter = (state, props, key, entry) => { |
||
12 | |||
13 | if (props && props.reducerKeys) { |
||
14 | if (typeof props.reducerKeys === 'string') { |
||
15 | return get(state[props.reducerKeys], key, entry); |
||
16 | } |
||
17 | else if (typeof props.reducerKeys === 'object' && |
||
18 | Object.keys(props.reducerKeys).length > 0 && |
||
19 | props.reducerKeys[key]) { |
||
20 | |||
21 | const dynamicKey = props.reducerKeys[key]; |
||
22 | const dynamicState = get(state, dynamicKey, entry); |
||
23 | |||
24 | return dynamicState; |
||
25 | } |
||
26 | } |
||
27 | |||
28 | const val = get(state, key, entry); |
||
29 | |||
30 | if (val) { |
||
31 | return val; |
||
32 | } |
||
33 | |||
34 | return null; |
||
35 | }; |
||
36 | |||
37 | export const get = (state, key, entry) => { |
||
38 | |||
39 | if (!state) { |
||
40 | return null; |
||
41 | } |
||
42 | |||
43 | const isImmutable = typeof state.get === 'function'; |
||
44 | const stateItem = isImmutable |
||
45 | ? state.get(key) |
||
46 | : state[key]; |
||
47 | |||
48 | if (!stateItem) { |
||
49 | return null; |
||
50 | } |
||
51 | |||
52 | return stateItem.get(entry); |
||
53 | }; |
||
54 |