-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgc-derive.html
More file actions
34 lines (32 loc) · 1.07 KB
/
gc-derive.html
File metadata and controls
34 lines (32 loc) · 1.07 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
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="/logo.svg">
<title>Demo for Garbage Collection (Bad Example for Derived State)</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script type="text/javascript" src="van-latest.nomodule.js"></script>
<script>
const {div, h4, input, pre, span} = van.tags
const renderPre = van.state(false)
const prefix = van.state("Prefix")
const TextDiv = () => div(() => {
const suffix = van.state("Suffix")
const text = van.derive(() => `${prefix.val} - ${suffix.val}`)
return (renderPre.val ? pre : span)(text)
})
van.add(document.body,
div(
"renderPre: ",
input({type: "checkbox", checked: renderPre, onclick: e => renderPre.val = e.target.checked}),
" prefix: ",
input({type: "text", value: prefix, oninput: e => prefix.val = e.target.value}),
),
h4("Rendering Result:"),
TextDiv(),
)
</script>
</body>
</html>