Total Complexity | 4 |
Complexity/F | 1.33 |
Lines of Code | 34 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
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 |