-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.tsx
42 lines (32 loc) · 816 Bytes
/
app.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
import domdom from '@eirikb/domdom';
type Route = 'panel-a' | 'panel-b';
interface Data {
route: Route;
}
const { React, init, don, path, data } = domdom<Data>({ route: 'panel-a' });
const PanelA = () => (
<div>
Panel A :) <button onclick={() => gotoRoute('panel-b')}>Next panel</button>
</div>
);
const PanelB = () => <div>Panel B! (hash is: {window.location.hash})</div>;
const view = (
<div>
{don(path().route).map((route: Route) => {
switch (route) {
case 'panel-b':
return <PanelB />;
default:
return <PanelA />;
}
})}
</div>
);
function gotoRoute(route: Route) {
window.location.hash = route;
}
window.addEventListener(
'hashchange',
() => (data.route = window.location.hash.slice(1) as Route)
);
init(document.body, view);