Files: 0a19ff71e90207bdc5e6b22d5470c11617f9f7b0 / app / store.js
1310 bytesRaw
1 | const { createStore, compose, applyMiddleware } = require('redux') |
2 | const thunk = require('redux-thunk') |
3 | const logger = require('redux-logger') |
4 | const { reduxReactRouter, routerStateReducer, ReduxRouter } = require('redux-router') |
5 | const { createHistory } = require('history') |
6 | |
7 | const rootReducer = require('app/reducers') |
8 | const routes = require('routes') |
9 | |
10 | let storesEnhancers = [] |
11 | let middleware = [] |
12 | |
13 | middleware.push(thunk) |
14 | |
15 | if (process.env.NODE_ENV === 'development') { |
16 | const { persistState } = require('redux-devtools') |
17 | |
18 | middleware.push(logger()) |
19 | } |
20 | |
21 | storesEnhancers.push( |
22 | applyMiddleware(middleware) |
23 | ) |
24 | |
25 | if (process.env.NODE_ENV === 'development') { |
26 | storesEnhancers.push(DevTools.instrument()) |
27 | storesEnhancers.push(persistState( |
28 | window.location.href.match( |
29 | /[?&]debug_session=([^&]+)\b/ |
30 | ) |
31 | )) |
32 | } |
33 | |
34 | storesEnhancers.push( |
35 | reduxReactRouter({ |
36 | routes, createHistory |
37 | }) |
38 | ) |
39 | |
40 | const finalCreateStore = compose( |
41 | ...storesEnhancers |
42 | )(createStore) |
43 | |
44 | function configureStore(initialState) { |
45 | const store = finalCreateStore(rootReducer, initialState) |
46 | |
47 | if (process.env.NODE_ENV === 'development') { |
48 | if (module.hot) { |
49 | module.hot.accept('app/reducers', () => |
50 | store.replaceReducer(require('app/reducers')) |
51 | ) |
52 | } |
53 | } |
54 | |
55 | return store |
56 | } |
57 | |
58 | module.exports = configureStore |
59 | |
60 |
Built with git-ssb-web