-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathhydro.html
More file actions
50 lines (49 loc) · 1.42 KB
/
hydro.html
File metadata and controls
50 lines (49 loc) · 1.42 KB
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
<!DOCTYPE html><html><head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Hello Hydro</title>
<script type="module">
await new Promise($ => setTimeout($, 2000));
import { render, html } from '../hydro.js';
function App(state) {
return html`
<h1>${state.title}</h1>
<div>
<ul>${[]}</ul>
<input autofocus>
<button onclick=${() => {
state.count++;
this.update(state);
}}>
Clicked ${state.count} times
</button>
</div>
`;
}
const component = (target, Callback) => {
const effect = {
target,
update(...args) {
render(target, Callback.apply(effect, args));
}
};
return Callback.bind(effect);
};
const state = {
"title": "Hello Hydro",
"count": 0
};
const { body } = document;
const Body = component(body, App);
render(body, Body(state));
</script>
</head><body><!--<>--><h1><!--{-->Hello Hydro<!--}--></h1>
<div>
<ul><!--[]--><!--[0]--></ul>
<input autofocus>
<button>
Clicked <!--{-->0<!--}--> times
</button>
</div><!--</>--></body>
<!--#-->
</html>