-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (57 loc) · 2.14 KB
/
index.js
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
// React
import React from "react";
import { render } from "react-dom";
// bootstrap & font-awesome & google font
import "bootstrap/dist/css/bootstrap.min.css";
import 'font-awesome/css/font-awesome.min.css';
import "typeface-montserrat";
import registerServiceWorker from "./registerServiceWorker";
// import injectTapEventPlugin from 'react-tap-event-plugin'
import i18n from "./i18n";
import Root from "./ui";
import configureStore, { history } from "./store";
import * as authSelectors from "./store/selectors/auth";
const rootElement = document.getElementById("root");
// Needed for onTouchTap
// https://github.com/zilverline/react-tap-event-plugin
// injectTapEventPlugin()
// work offline WPA
registerServiceWorker();
// config for store
configureStore(
store => {
// const history = syncHistoryWithStore(browserHistory, store)
// scroll to top on new location, but preserve scroll position on back action
// for better user-experience, do this on OnChange event of router, when component is rendered
history.listen(
location => location.action !== "POP" && window.scrollTo(0, 0)
);
// update language from i18n to store
i18n.on("languageChanged", lng => {
const currentLanguage = authSelectors.getCustomer(store.getState()).language;
if (currentLanguage !== lng) {
store.dispatch({
type: "app/setLanguage",
payload: lng
});
}
});
// ready to render
render(<Root store={store} history={history} />, rootElement);
// enable hot reload for react code
if (module.hot) {
// tracking css changes
// tracking code changes
module.hot.accept("./ui", () => {
// if we use es2015 => this is native so there will be cache, we have to use another instance
// to force rebuild, other wise just use prev Root
// this NextRoot is other Component to render, start tracking with inside AppContainer
const NextRoot = require("./ui").default;
render(<NextRoot store={store} history={history} />, rootElement);
});
}
},
err => {
render(<h1 style={{ color: "red" }}>{err}</h1>, rootElement);
}
);