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';
|
|
|
|
import { persistState } from 'redux-devtools';
|
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 =
|
|
|
|
process.env.NODE_ENV === 'production' ? '/redux-devtools-inspector/' : '/';
|
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 =
|
2020-08-31 00:49:06 +03:00
|
|
|
!!((window as unknown) as { __REDUX_DEVTOOLS_EXTENSION__: unknown })
|
|
|
|
.__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
|
2020-08-31 00:49:06 +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
|
|
|
);
|