Files: e077e8e4d717d2c79b41f7287c20906ac86841db / app / store.js
1367 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 | var { persistState } = require('redux-devtools') |
17 | |
18 | var DevTools = require('app/containers/dev-tools') |
19 | |
20 | middleware.push(logger()) |
21 | } |
22 | |
23 | storesEnhancers.push( |
24 | applyMiddleware(...middleware) |
25 | ) |
26 | |
27 | if (process.env.NODE_ENV === 'development') { |
28 | storesEnhancers.push(DevTools.instrument()) |
29 | storesEnhancers.push(persistState( |
30 | window.location.href.match( |
31 | /[?&]debug_session=([^&]+)\b/ |
32 | ) |
33 | )) |
34 | } |
35 | |
36 | storesEnhancers.push( |
37 | reduxReactRouter({ |
38 | routes, createHistory |
39 | }) |
40 | ) |
41 | |
42 | const finalCreateStore = compose( |
43 | ...storesEnhancers |
44 | )(createStore) |
45 | |
46 | function configureStore(initialState) { |
47 | const store = finalCreateStore(rootReducer, initialState) |
48 | |
49 | if (process.env.NODE_ENV === 'development') { |
50 | if (module.hot) { |
51 | module.hot.accept('app/reducers', () => |
52 | store.replaceReducer(require('app/reducers')) |
53 | ) |
54 | } |
55 | } |
56 | |
57 | return store |
58 | } |
59 | |
60 | module.exports = configureStore |
61 | |
62 |
Built with git-ssb-web