-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo_ssr.html
57 lines (56 loc) · 1.6 KB
/
todo_ssr.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" type="image/x-icon" href="../favicon.ico">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
<title>Todo SSR - The Merlin JS framework</title>
</head>
<body>
<h1><img src="../favicon.ico"> To do list (Server-Side Rendered)</h1>
<main>
<input type="text">
<ul>
<li>read a book</li>
<li>plant a tree</li>
</ul>
<button>New!</button>
</main>
<template>
<input type="text" value:="value" oninput:="NewValue">
<ul>
<li each:="todos" text:></li>
</ul>
<button onclick:="AddTodo">New!</button>
</template>
<script type="module">
import {app} from "../index.js"
const main = document.body.querySelector('main')
app({
node: main,
template: document.body.querySelector('template'),
init: {
value: '',
todos: Array.from(main.querySelectorAll('li'))
.map(e => e.textContent)
},
register: update => ({
NewValue: ev => update(state => ({
...state,
value: ev.target.value
})),
AddTodo: () => update(({todos, value}) => ({
todos: todos.concat(value),
value: ''
}))
}),
view: (state, events) => ({
...state,
...events
})
})
</script>
</body>
</html>