2020-08-08 22:46:01 +03:00
|
|
|
import React from 'react';
|
2022-06-06 19:22:05 +03:00
|
|
|
import { createRoot } from 'react-dom/client';
|
2021-09-18 17:00:58 +03:00
|
|
|
import { Container } from '@redux-devtools/ui';
|
2020-08-08 22:46:01 +03:00
|
|
|
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';
|
2022-05-16 00:47:09 +03:00
|
|
|
import { BrowserRouter, Route, Routes } from 'react-router-dom';
|
2020-12-21 17:08:08 +03:00
|
|
|
import { persistState } from '@redux-devtools/core';
|
2020-09-13 07:02:24 +03:00
|
|
|
import DemoApp from './DemoApp';
|
2022-05-15 23:16:18 +03:00
|
|
|
import { rootReducer } 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'
|
2020-10-04 07:01:46 +03:00
|
|
|
? '/redux-devtools-inspector-monitor-test-tab/'
|
2020-08-10 03:41:59 +03:00
|
|
|
: '/';
|
|
|
|
|
|
|
|
const DevTools = getDevTools(window.location);
|
2020-08-08 22:46:01 +03:00
|
|
|
|
2020-08-10 03:41:59 +03:00
|
|
|
const useDevtoolsExtension =
|
2021-06-18 06:56:36 +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
|
|
|
|
2024-08-06 06:11:13 +03:00
|
|
|
const enhancer: StoreEnhancer = compose(
|
2022-05-15 23:16:18 +03:00
|
|
|
applyMiddleware(logger),
|
2024-08-06 06:11:13 +03:00
|
|
|
((next) => {
|
2020-08-08 22:46:01 +03:00
|
|
|
const instrument = useDevtoolsExtension
|
2021-06-18 06:56:36 +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);
|
2024-08-06 06:11:13 +03:00
|
|
|
}) as StoreEnhancer,
|
2023-07-12 21:03:20 +03:00
|
|
|
persistState(getDebugSessionKey()),
|
2024-08-06 06:11:13 +03:00
|
|
|
) as any;
|
2020-08-08 22:46:01 +03:00
|
|
|
|
2022-05-15 23:16:18 +03:00
|
|
|
const store = createStore(rootReducer, enhancer);
|
2020-08-08 22:46:01 +03:00
|
|
|
|
2022-06-06 19:22:05 +03:00
|
|
|
const root = createRoot(document.getElementById('root')!);
|
|
|
|
root.render(
|
2020-08-10 03:41:59 +03:00
|
|
|
<Provider store={store}>
|
2022-05-15 23:16:18 +03:00
|
|
|
<BrowserRouter>
|
2020-08-08 22:46:01 +03:00
|
|
|
<Container
|
2021-11-06 20:28:35 +03:00
|
|
|
themeData={{
|
|
|
|
theme: 'default',
|
|
|
|
scheme: 'default',
|
|
|
|
colorPreference: 'auto',
|
|
|
|
}}
|
2020-08-08 22:46:01 +03:00
|
|
|
>
|
2022-05-16 00:47:09 +03:00
|
|
|
<Routes>
|
|
|
|
<Route path={ROOT} element={<DemoApp />} />
|
|
|
|
</Routes>
|
2020-08-10 03:41:59 +03:00
|
|
|
{!useDevtoolsExtension && <ConnectedDevTools />}
|
2020-08-08 22:46:01 +03:00
|
|
|
</Container>
|
2022-05-15 23:16:18 +03:00
|
|
|
</BrowserRouter>
|
2023-07-12 21:03:20 +03:00
|
|
|
</Provider>,
|
2020-08-10 03:41:59 +03:00
|
|
|
);
|