src/helpers/store.js   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 1.33

Size

Lines of Code 34
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
wmc 4
c 2
b 0
f 0
nc 1
mnd 1
bc 5
fnc 3
dl 0
loc 34
rs 10
bpm 1.6666
cpm 1.3333
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A store.js ➔ buildStore 0 6 1
A store.js ➔ createReducer 0 9 1
1
import { combineReducers, applyMiddleware, createStore } from 'redux';
2
import { browserHistory } from 'react-router';
3
import { routerMiddleware } from 'react-router-redux';
4
import thunk from 'redux-thunk';
5
import apiMiddleware from '../middleware/api';
6
import * as reducers from '../state/reducers';
7
8
/**
9
 *
10
 * @param {*} initialState
11
 * @param {Object} handlers
12
 * @returns {function}
13
 * @see http://redux.js.org/docs/recipes/ReducingBoilerplate.html
14
 */
15
export function createReducer(initialState, handlers) {
16
  return function reducer(state = initialState, action) {
17
    if (handlers.hasOwnProperty(action.type)) {
18
      return handlers[action.type](state, action);
19
    } else {
20
      return state;
21
    }
22
  };
23
}
24
25
/**
26
 *
27
 * @returns {function}
28
 */
29
export function buildStore() {
30
  const rootReducer = combineReducers(reducers);
31
  const routerHistoryMiddleware = routerMiddleware(browserHistory);
32
33
  return applyMiddleware(thunk, apiMiddleware, routerHistoryMiddleware)(createStore)(rootReducer);
34
}
35