This repository was archived by the owner on Dec 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclient.tsx
executable file
·68 lines (56 loc) · 2.15 KB
/
client.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import 'bootstrap/dist/css/bootstrap.css';
import './assets/styles/screen.scss';
import 'fetch-everywhere';
import * as bootstrap from 'react-async-bootstrapper';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import {createBrowserHistory, History} from 'history';
import {AppContainer as ReactHotLoader} from 'react-hot-loader';
import {AsyncComponentProvider} from 'react-async-component';
import RouterWrapper from './RouterWrapper';
import ProviderUtility from './utilities/ProviderUtility';
import IStore from './stores/IStore';
import ISagaStore from './stores/ISagaStore';
import rootReducer from './stores/rootReducer';
(async (window: Window) => {
const codeSplittingState = window.__ASYNC_COMPONENTS_STATE__;
const serverState: IStore = window.__STATE__;
const initialState: IStore = {
...serverState,
renderReducer: {
...serverState.renderReducer,
isServerSide: false,
},
};
const history: History = createBrowserHistory();
const store: ISagaStore = ProviderUtility.createProviderStore(initialState, history);
const rootEl: HTMLElement = document.getElementById('root');
delete window.__STATE__;
delete window.__ASYNC_COMPONENTS_STATE__;
const composeApp = (Component: any) => (
<ReactHotLoader key={Math.random()}>
<AsyncComponentProvider rehydrateState={codeSplittingState}>
<Component
store={store}
history={history}
/>
</AsyncComponentProvider>
</ReactHotLoader>
);
const renderApp = () => {
const routerWrapper = require('./RouterWrapper').default; // tslint:disable-line:no-require-imports
ReactDOM.hydrate(
composeApp(routerWrapper),
rootEl,
);
};
bootstrap(composeApp(RouterWrapper)).then(renderApp);
if (module.hot) {
// Reload components
module.hot.accept('./RouterWrapper', renderApp);
// Reload reducers
module.hot.accept('./stores/rootReducer', () => {
store.replaceReducer(rootReducer(history));
});
}
})(window);