summaryrefslogtreecommitdiff
path: root/frontend/src/store.js
blob: e9ac401e08308971f6984b45bf5f6f072c8d7238 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { createStore, applyMiddleware, compose } from 'redux'
import { browserHistory} from 'react-router'
import { syncHistoryWithStore, routerMiddleware } from 'react-router-redux'

import createReducer from './reducers'
import createSagaMiddleware from 'redux-saga'
import rootSaga from './sagas'

export default function configureStore(initialState = {}) {
  const sagaMiddleware = createSagaMiddleware()
  const history = browserHistory

  const middlewares = [
    sagaMiddleware,
    routerMiddleware(history)
  ]

  const enhancers = [
    applyMiddleware(...middlewares)
  ]

  const composeEnhancers =
    process.env.NODE_ENV !== 'production' &&
    typeof window === 'object' &&
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
      window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : compose;

  const store = createStore(
    createReducer(),
    initialState,
    composeEnhancers(...enhancers)
  )

  sagaMiddleware.run(rootSaga)

  return {
    store,
    history: syncHistoryWithStore(history, store)
  }
}
bgstack15