-
Notifications
You must be signed in to change notification settings - Fork 5
/
demo.go
84 lines (70 loc) · 1.29 KB
/
demo.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// +build ignore
package main
import (
"syscall/js"
"time"
"github.com/reusee/domui"
)
// RootElement is the element to be rendered to RenderElement
func RootElementDecl(
// use CounterElement as depenency
counter CounterElement,
) domui.RootElement {
return Div(
P(
S("hello, world!"),
),
counter,
)
}
// Num is an integer state
type Num int
// Num initial value
func NumDecl() Num {
return 0
}
// CounterElement is a button displaying and mutating Num
type CounterElement domui.Spec
func CounterElementDecl(
// use Num as depenency
num Num,
// use Update function
update Update,
) CounterElement {
return Button(
// label
S("%d", num),
// style
FontSize("%.2frem", float64(num)*0.5+1),
Color("#09C"),
// increase Num on click
OnClick(func() {
num++
update(&num)
}),
)
}
func main() {
domui.NewApp(
// render element
js.Global().Get("document").Call("getElementById", "app"),
// list all declarations
RootElementDecl,
NumDecl,
CounterElementDecl,
)
time.Sleep(time.Hour * 24 * 365 * 200)
}
// aliases
var (
Div = domui.Tag("div")
P = domui.Tag("p")
S = domui.S
Button = domui.Tag("button")
OnClick = domui.On("click")
FontSize = domui.Style("font-size")
Color = domui.Style("color")
)
type (
Update = domui.Update
)