File size: 1,125 Bytes
1e92f2d |
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 |
// @flow
/* eslint-disable */
import { createStore, compose, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import crashReporter from 'src/helpers/sentry-redux-middleware';
import getReducers from '../reducers';
// this enables the chrome devtools for redux only in development
const composeEnhancers =
(process.env.NODE_ENV !== 'production' &&
typeof window !== 'undefined' &&
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
compose;
// init the store with the thunkMiddleware which allows us to make async actions play nicely with the store
// Allow dependency injection of extra reducers and middleware, we need this for SSR
export const initStore = (initialState?: Object) => {
let store = createStore(
getReducers(),
initialState || {},
composeEnhancers(applyMiddleware(thunkMiddleware, crashReporter))
);
if (module.hot && typeof module.hot.accept === 'function') {
module.hot.accept('../reducers', () => {
const nextGetReducers = require('../reducers/index').default;
store.replaceReducer(nextGetReducers());
});
}
return store;
};
|