summaryrefslogtreecommitdiff
path: root/frontend/src/store.js
blob: 2a5bf4bb4f8c60657514089a38404d3e42653c05 (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
// @flow
import createHistory from 'history/createBrowserHistory';
import { routerMiddleware } from 'react-router-redux';
import { applyMiddleware, createStore } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import createSagaMiddleware from 'redux-saga';
import type { GlobalState } from './reducers';
import { createReducer } from './reducers';
import { rootSaga } from './sagas';

export function configureStore(initialState: GlobalState = {}) {
  const sagaMiddleware = createSagaMiddleware();

  const history = createHistory();

  const middlewares = [sagaMiddleware, routerMiddleware(history)];

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

  const store = createStore(createReducer(), initialState, composeWithDevTools(...enhancers));

  sagaMiddleware.run(rootSaga);

  return {
    store,
    history,
  };
}
bgstack15