/
boot-client.tsx
77 lines (64 loc) · 2.42 KB
/
boot-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
69
70
71
72
73
74
75
76
77
import "@babel/polyfill";
import "custom-event-polyfill";
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import { Provider } from 'react-redux';
import { ConnectedRouter } from 'connected-react-router';
import { createBrowserHistory } from 'history';
import configureStore from './configureStore';
import { ApplicationState } from './store';
import * as RoutesModule from './routes';
let routes = RoutesModule.routes;
import "@Styles/main.scss";
import 'react-toastify/dist/ReactToastify.css';
import Globals from "@Globals";
import { isNode } from '@Utils';
import { IPublicSession } from "@Models/IPublicSession";
import { IPrivateSession } from "@Models/IPrivateSession";
import { NSerializeJson } from "nserializejson";
function setupSession() {
if (!isNode()) {
Globals.reset();
Globals.init({ public: window["publicSession"] as IPublicSession, private: {} as IPrivateSession });
}
};
function setupGlobalPlugins() {
// Use dot notation in the name attributes of the form inputs.
NSerializeJson.options.useDotSeparatorInPath = true;
};
function setupEvents() {
document.addEventListener('DOMContentLoaded', () => {
var preloader = document.getElementById("preloader");
preloader.classList.add("hidden");
});
};
// Create browser history to use in the Redux store.
const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href')!;
const history = createBrowserHistory({ basename: baseUrl });
// Get the application-wide store instance, prepopulating with state from the server where available.
const initialState = (window as any).initialReduxState as ApplicationState;
const store = configureStore(history, initialState);
function renderApp() {
// This code starts up the React app when it runs in a browser. It sets up the routing configuration
// and injects the app into a DOM element.
ReactDOM.hydrate(
<AppContainer>
<Provider store={ store }>
<ConnectedRouter history={ history } children={ routes } />
</Provider>
</AppContainer>,
document.getElementById('react-app')
);
}
setupSession();
setupGlobalPlugins();
setupEvents();
renderApp();
// Allow Hot Module Replacement.
if (module.hot) {
module.hot.accept('./routes', () => {
routes = require<typeof RoutesModule>('./routes').routes;
renderApp();
});
}