2018-12-22 03:10:49 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { render } from 'react-dom';
|
|
|
|
import { Provider } from 'react-redux';
|
2020-08-31 00:49:06 +03:00
|
|
|
import {
|
|
|
|
createStore,
|
|
|
|
applyMiddleware,
|
|
|
|
compose,
|
|
|
|
StoreEnhancerStoreCreator,
|
|
|
|
StoreEnhancer,
|
|
|
|
} from 'redux';
|
2020-08-09 01:04:46 +03:00
|
|
|
import logger from 'redux-logger';
|
2020-08-10 03:41:59 +03:00
|
|
|
import { Route } from 'react-router';
|
|
|
|
import { createBrowserHistory } from 'history';
|
|
|
|
import { ConnectedRouter, routerMiddleware } from 'connected-react-router';
|
2020-12-21 17:08:08 +03:00
|
|
|
import { persistState } from '@redux-devtools/core';
|
2020-08-31 00:49:06 +03:00
|
|
|
import DemoApp from './DemoApp';
|
|
|
|
import createRootReducer from './reducers';
|
2018-12-22 03:10:49 +03:00
|
|
|
import getOptions from './getOptions';
|
2020-08-10 03:41:59 +03:00
|
|
|
import { ConnectedDevTools, getDevTools } from './DevTools';
|
2018-12-22 03:10:49 +03:00
|
|
|
|
|
|
|
function getDebugSessionKey() {
|
2020-08-31 00:49:06 +03:00
|
|
|
const matches = /[?&]debug_session=([^&#]+)\b/.exec(window.location.href);
|
2019-01-10 21:51:14 +03:00
|
|
|
return matches && matches.length > 0 ? matches[1] : null;
|
2018-12-22 03:10:49 +03:00
|
|
|
}
|
|
|
|
|
2019-01-10 21:51:14 +03:00
|
|
|
const ROOT =
|
2020-09-10 19:37:19 +03:00
|
|
|
process.env.NODE_ENV === 'production'
|
|
|
|
? '/redux-devtools-inspector-monitor/'
|
|
|
|
: '/';
|
2018-12-22 03:10:49 +03:00
|
|
|
|
2020-08-10 03:41:59 +03:00
|
|
|
const DevTools = getDevTools(window.location);
|
2018-12-22 03:10:49 +03:00
|
|
|
|
2020-08-10 03:41:59 +03:00
|
|
|
const history = createBrowserHistory();
|
|
|
|
|
|
|
|
const useDevtoolsExtension =
|
2021-06-18 06:56:36 +03:00
|
|
|
!!(window as unknown as { __REDUX_DEVTOOLS_EXTENSION__: unknown })
|
2020-08-31 00:49:06 +03:00
|
|
|
.__REDUX_DEVTOOLS_EXTENSION__ && getOptions(window.location).useExtension;
|
2018-12-22 03:10:49 +03:00
|
|
|
|
|
|
|
const enhancer = compose(
|
2020-08-10 03:41:59 +03:00
|
|
|
applyMiddleware(logger, routerMiddleware(history)),
|
2020-08-31 00:49:06 +03:00
|
|
|
(next: StoreEnhancerStoreCreator) => {
|
2019-01-10 21:51:14 +03:00
|
|
|
const instrument = useDevtoolsExtension
|
2021-06-18 06:56:36 +03:00
|
|
|
? (
|
|
|
|
window as unknown as {
|
|
|
|
__REDUX_DEVTOOLS_EXTENSION__(): StoreEnhancer;
|
|
|
|
}
|
|
|
|
).__REDUX_DEVTOOLS_EXTENSION__()
|
2019-01-10 21:51:14 +03:00
|
|
|
: DevTools.instrument();
|
2020-08-31 00:49:06 +03:00
|
|
|
return instrument(next);
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
|
|
|
persistState(getDebugSessionKey())
|
|
|
|
);
|
|
|
|
|
2020-08-31 00:49:06 +03:00
|
|
|
const store = createStore(createRootReducer(history), enhancer);
|
2020-08-10 03:41:59 +03:00
|
|
|
|
|
|
|
render(
|
|
|
|
<Provider store={store}>
|
|
|
|
<ConnectedRouter history={history}>
|
|
|
|
<Route path={ROOT}>
|
|
|
|
<DemoApp />
|
|
|
|
</Route>
|
|
|
|
{!useDevtoolsExtension && <ConnectedDevTools />}
|
|
|
|
</ConnectedRouter>
|
|
|
|
</Provider>,
|
|
|
|
document.getElementById('root')
|
2019-01-10 21:51:14 +03:00
|
|
|
);
|