-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
41 lines (35 loc) · 956 Bytes
/
main.go
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
package main
import (
"syscall/js"
"github.com/syumai/go-hyperscript/dom"
h "github.com/syumai/go-hyperscript/hyperscript"
)
var (
body = js.Global().Get("document").Get("body")
renderer = dom.NewRenderer()
)
func mapToList(names ...string) h.VNodes {
elements := make(h.VNodes, len(names))
for i, name := range names {
elements[i] = h.H("li", nil, h.Text(name))
}
return elements
}
func List(props h.Object) h.VNode {
return h.H("ul", nil, mapToList(props.Strings("names")...)...)
}
func main() {
node := h.H("div", nil,
h.H("h1", nil, h.Text("Example App")),
h.H("strong", nil,
h.H("font", h.Object{"color": "red"}, h.Text("Hello, world!")),
),
h.H("h2", nil, h.Text("List")),
h.H(List, h.Object{"names": []string{"a", "b", "c"}}),
h.H("h2", nil, h.Text("Count")),
h.H("a", h.Object{"href": "https://github.com/syumai/go-hyperscript/"},
h.Text("Show the code on GitHub"),
),
)
renderer.Render(node, body)
}