-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (41 loc) · 1.22 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
import { createStore, reducer, searchRankingsAction, sortResultsAction } from "./js/state.js";
import { createRoot, App, Loading, ErrorMessage } from "./js/app.js";
/** @type {GlobalRankingsSnapshot} This is the only direct reference to the global */
const rankingData = window.rankings || null;
/** @type {Root} */
const root = createRoot("#app");
if (!rankingData) {
root.render(ErrorMessage("The ranking data is missing, try back in a bit."));
console.error(`rankings: ${window.rankings}`);
throw "";
}
/** @type {AppState} */
const initialState = {
results: null,
dataLastUpdated: rankingData.refreshed,
topN: 10,
recentInDays: 30,
sortProp: "date",
sortDirection: -1,
};
const store = createStore(initialState, reducer);
render();
function render() {
try {
const { results, sortProp } = store.getState();
root.render(Loading());
if (!results) {
store.dispatch(searchRankingsAction(rankingData));
if (sortProp) {
store.dispatch(sortResultsAction(sortProp));
}
}
root.render(App({ store: store, handleRender: render }));
}
catch (error) {
root.render(ErrorMessage(error));
// Re-throw the error uncaught to stop execution and
// get line number information in the console
throw error;
}
}