-
Notifications
You must be signed in to change notification settings - Fork 0
/
counter.html
30 lines (30 loc) · 920 Bytes
/
counter.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Patella Example - Counter</title>
<script src="https://cdn.jsdelivr.net/npm/patella@2.2.2"></script>
</head>
<body>
<main>
<h1>Click Counter</h1>
<button onclick="model.clicks++"></button>
</main>
<script>
const $button = document.getElementsByTagName("button")[0];
const model = Patella.observe({
clicks: 0
});
Patella.computed(() => {
$button.innerText = model.clicks
? `I've been clicked ${model.clicks} times`
: "Click me!";
});
</script>
<footer>
<a href="https://github.com/luawtf/Patella/blob/master/examples/counter.html">View source</a>
</footer>
</body>
</html>