-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomponents.html
More file actions
47 lines (45 loc) · 1.4 KB
/
components.html
File metadata and controls
47 lines (45 loc) · 1.4 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
<!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>Components - The Merlin JS framework</title>
</head>
<body>
<main>
<h1><img src="../favicon.ico"> Components sample</h1>
<div data-init="0"></div>
<div data-init="3"></div>
<div data-init="7"></div>
</main>
<template id="comp-counter">
<h1>Counter: <span text:="count"></span></h1>
<button onclick:="dec">-</button>
<button onclick:="inc">+</button>
</template>
<script type="module">
import {app} from "../index.js"
const counter = component => app({
...component,
template: document.getElementById('comp-counter'),
register: update => ({
inc: () => update(count => count + 1),
dec: () => update(count => count - 1)
}),
view: (count, events) => ({
count,
...events
})
})
document.body.querySelectorAll('[data-init]').forEach(node => {
counter({
node,
init: parseInt(node.getAttribute('data-init'))
})
})
</script>
</body>
</html>