summaryrefslogtreecommitdiff
path: root/sw-ui/src/store.ts
blob: 54a655094389be15d18c2c113aa149fcb266f4f8 (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
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 { 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