2020-08-08 22:46:01 +03:00
|
|
|
import 'devui/lib/presets';
|
|
|
|
import React from 'react';
|
|
|
|
import { render } from 'react-dom';
|
|
|
|
import { Container } from 'devui';
|
|
|
|
import { Provider } from 'react-redux';
|
2020-09-13 07:02:24 +03:00
|
|
|
import {
|
|
|
|
createStore,
|
|
|
|
applyMiddleware,
|
|
|
|
compose,
|
|
|
|
StoreEnhancer,
|
|
|
|
StoreEnhancerStoreCreator,
|
|
|
|
} 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-09-13 07:02:24 +03:00
|
|
|
import DemoApp from './DemoApp';
|
|
|
|
import createRootReducer from './reducers';
|
2020-08-08 22:46:01 +03:00
|
|
|
import getOptions from './getOptions';
|
2020-08-10 03:41:59 +03:00
|
|
|
import { ConnectedDevTools, getDevTools } from './DevTools';
|
2020-08-08 22:46:01 +03:00
|
|
|
|
|
|
|
function getDebugSessionKey() {
|
2020-09-13 07:02:24 +03:00
|
|
|
const matches = /[?&]debug_session=([^&#]+)\b/.exec(window.location.href);
|
2020-08-08 22:46:01 +03:00
|
|
|
return matches && matches.length > 0 ? matches[1] : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ROOT =
|
2020-08-10 03:41:59 +03:00
|
|
|
process.env.NODE_ENV === 'production'
|
|
|
|
? '/redux-devtools-test-generator/'
|
|
|
|
: '/';
|
|
|
|
|
|
|
|
const DevTools = getDevTools(window.location);
|
2020-08-08 22:46:01 +03:00
|
|
|
|
2020-08-10 03:41:59 +03:00
|
|
|
const history = createBrowserHistory();
|
2020-08-08 22:46:01 +03:00
|
|
|
|
2020-08-10 03:41:59 +03:00
|
|
|
const useDevtoolsExtension =
|
2020-09-13 07:02:24 +03:00
|
|
|
!!((window as unknown) as { __REDUX_DEVTOOLS_EXTENSION__: unknown }) &&
|
2020-08-10 03:41:59 +03:00
|
|
|
getOptions(window.location).useExtension;
|
2020-08-08 22:46:01 +03:00
|
|
|
|
|
|
|
const enhancer = compose(
|
2020-08-10 03:41:59 +03:00
|
|
|
applyMiddleware(logger, routerMiddleware(history)),
|
2020-09-13 07:02:24 +03:00
|
|
|
(next: StoreEnhancerStoreCreator) => {
|
2020-08-08 22:46:01 +03:00
|
|
|
const instrument = useDevtoolsExtension
|
2020-09-13 07:02:24 +03:00
|
|
|
? ((window as unknown) as {
|
|
|
|
__REDUX_DEVTOOLS_EXTENSION__(): StoreEnhancer;
|
|
|
|
}).__REDUX_DEVTOOLS_EXTENSION__()
|
2020-08-08 22:46:01 +03:00
|
|
|
: DevTools.instrument();
|
2020-09-13 07:02:24 +03:00
|
|
|
return instrument(next);
|
2020-08-08 22:46:01 +03:00
|
|
|
},
|
|
|
|
persistState(getDebugSessionKey())
|
|
|
|
);
|
|
|
|
|
2020-09-13 07:02:24 +03:00
|
|
|
const store = createStore(createRootReducer(history), enhancer);
|
2020-08-08 22:46:01 +03:00
|
|
|
|
2020-08-10 03:41:59 +03:00
|
|
|
render(
|
|
|
|
<Provider store={store}>
|
|
|
|
<ConnectedRouter history={history}>
|
2020-08-08 22:46:01 +03:00
|
|
|
<Container
|
|
|
|
themeData={{ theme: 'default', scheme: 'default', light: true }}
|
|
|
|
>
|
2020-08-10 03:41:59 +03:00
|
|
|
<Route path={ROOT}>
|
|
|
|
<DemoApp />
|
|
|
|
</Route>
|
|
|
|
{!useDevtoolsExtension && <ConnectedDevTools />}
|
2020-08-08 22:46:01 +03:00
|
|
|
</Container>
|
2020-08-10 03:41:59 +03:00
|
|
|
</ConnectedRouter>
|
|
|
|
</Provider>,
|
|
|
|
document.getElementById('root')
|
|
|
|
);
|