-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (45 loc) · 1.44 KB
/
app.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
import { render } from "./packages.js";
import { getState, subscribe, dispatch } from "./store.js";
import { app } from "./templates/app.js";
const add = (a, b) => a + b;
const sum = values => {
return values.reduce(add, 0);
};
const average = values => {
const total = sum(values);
return Math.round(total / values.length);
};
const measure = () => {
const end = Date.now();
const duration = end - window.start;
const durations = JSON.parse(localStorage.getItem("durations")) || [];
durations.push(duration);
console.log(
"durations.length",
durations.length,
"average",
average(durations)
);
console.log("durations", durations);
localStorage.setItem("durations", JSON.stringify(durations));
};
const renderApp = ({ state, dispatch }) => {
render(app({ state, dispatch }), document.getElementById("app"));
};
const handleStore = () => renderApp({ state: getState(), dispatch });
subscribe(handleStore);
const reapplyScrollTopAfterPublish = ({ getState, action }) => {
if (action.type === 'PUBLISH') {
const preview = document.getElementById("preview-interior");
const isScrollTopOff = preview.scrollTop !== getState().testStringPanelScrollTop;
if (isScrollTopOff) {
preview.scrollTop = getState().testStringPanelScrollTop;
}
}
};
subscribe(reapplyScrollTopAfterPublish);
//subscribe(({ getState, action }) => {
//console.log('action', action, 'state', getState());
//});
handleStore();
measure();