Total Complexity | 13 |
Complexity/F | 6.5 |
Lines of Code | 46 |
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 | props.reducerKeys.length > 0) { |
||
16 | |||
17 | return get(state[props.reducerKeys], key, entry); |
||
18 | |||
19 | } |
||
20 | else if (typeof props.reducerKeys === 'object' && |
||
21 | Object.keys(props.reducerKeys).length > 0 && |
||
22 | props.reducerKeys[key]) { |
||
23 | |||
24 | const dynamicKey = props.reducerKeys[key]; |
||
25 | const dynamicState = get(state, dynamicKey, entry); |
||
26 | |||
27 | return dynamicState; |
||
28 | } |
||
29 | } |
||
30 | |||
31 | const val = get(state, key, entry); |
||
32 | |||
33 | if (val) { |
||
34 | return val; |
||
35 | } |
||
36 | |||
37 | return null; |
||
38 | }; |
||
39 | |||
40 | export const get = (state, key, entry) => { |
||
41 | |||
42 | if (!state) { |
||
43 | return null; |
||
44 | } |
||
45 | |||
46 | const isImmutable = typeof state.get === 'function'; |
||
47 | const stateItem = isImmutable |
||
48 | ? state.get(key) |
||
49 | : state[key]; |
||
50 | |||
51 | if (!stateItem) { |
||
52 | return null; |
||
53 | } |
||
54 | |||
55 | return stateItem.get(entry); |
||
56 | }; |
||
57 |