src/ReducerClass.js   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 24
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 13
mnd 2
bc 2
fnc 3
dl 0
loc 24
bpm 0.6666
cpm 1.6666
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A ReducerClass.js ➔ ReducerClass 0 21 5
1
import { DecoratorHelper, pathReducerMethods, toUnderscoreCase } from './utils'
2
3
4
export default function ReducerClass(prefix) {
5
  prefix = toUnderscoreCase(prefix)
6
7
  return function (target) {
8
    if (DecoratorHelper.isDecorated(target)) {
9
      return target
10
    }
11
12
    const reducerMap = pathReducerMethods(target, prefix)
13
    const initialState = DecoratorHelper.getStaticField(target, 'initialState')
14
15
    const reducer = (state = initialState, action) => (
16
      (action && reducerMap[action.type]) ? reducerMap[action.type](state, action) : state
17
    )
18
19
    DecoratorHelper.setStaticMethod(target, '$reducer', reducer)
20
    DecoratorHelper.markAsDecorated(target)
21
22
    return target
23
  }
24
}
25