2020-09-10 18:45:02 +03:00
|
|
|
import { createStore, compose, PreloadedState } from 'redux';
|
2020-12-21 17:08:08 +03:00
|
|
|
import { persistState } from '@redux-devtools/core';
|
2020-09-10 18:45:02 +03:00
|
|
|
import rootReducer, { TodoState } from '../reducers';
|
|
|
|
import DevTools from '../containers/DevTools';
|
|
|
|
|
|
|
|
function getDebugSessionKey() {
|
|
|
|
const matches = /[?&]debug_session=([^&#]+)\b/.exec(window.location.href);
|
|
|
|
return matches && matches.length > 0 ? matches[1] : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const enhancer = compose(
|
|
|
|
DevTools.instrument(),
|
|
|
|
persistState(getDebugSessionKey())
|
|
|
|
);
|
|
|
|
|
|
|
|
export default function configureStore(
|
|
|
|
initialState?: PreloadedState<TodoState>
|
|
|
|
) {
|
|
|
|
const store = createStore(rootReducer, initialState, enhancer);
|
|
|
|
|
|
|
|
if (module.hot) {
|
|
|
|
module.hot.accept('../reducers', () => store.replaceReducer(rootReducer));
|
|
|
|
}
|
|
|
|
|
|
|
|
return store;
|
|
|
|
}
|