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