mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-11 20:27:07 +03:00
27 lines
751 B
TypeScript
27 lines
751 B
TypeScript
|
import { createStore, compose, PreloadedState } from 'redux';
|
||
|
import { persistState } from 'redux-devtools';
|
||
|
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;
|
||
|
}
|