-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot.go
141 lines (122 loc) · 6.29 KB
/
root.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package main
// DO NOT EDIT: This file was generated by vugu. Please regenerate instead of editing or add additional code in a separate file.
import "fmt"
import "reflect"
import "github.com/vugu/vugu"
import "encoding/json"
import "net/http"
import "log"
type RootData struct {
dadJoke DadJoke
isLoading bool
}
type DadJoke struct {
Joke string `json:"joke"`
}
func (data *RootData) HandleClick(event *vugu.DOMEvent) {
data.dadJoke = DadJoke{}
ee := event.EventEnv()
go func() {
ee.Lock()
data.isLoading = true
ee.UnlockRender()
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://icanhazdadjoke.com", nil)
req.Header.Set("Accept", "application/json")
res, err := client.Do(req)
if err != nil {
log.Printf("Error fetch()ing: %v", err)
return
}
defer res.Body.Close()
var newb DadJoke
err = json.NewDecoder(res.Body).Decode(&newb)
if err != nil {
log.Printf("Error JSON decoding: %v", err)
return
}
ee.Lock()
defer ee.UnlockRender()
data.dadJoke = newb
data.isLoading = false
}()
}
var _ vugu.ComponentType = (*Root)(nil)
func (comp *Root) BuildVDOM(dataI interface{}) (vdom *vugu.VGNode, css *vugu.VGNode, reterr error) {
data := dataI.(*RootData)
_ = data
_ = fmt.Sprint
_ = reflect.Value{}
event := vugu.DOMEventStub
_ = event
css = &vugu.VGNode{Type: vugu.VGNodeType(3), Data: "style", DataAtom: vugu.VGAtom(458501), Namespace: "", Attr: []vugu.VGAttribute(nil)}
css.AppendChild(&vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n .container--box .box .spinner--1 {\n border-top: 2px solid #fff;\n animation: spinner1 600ms linear infinite;\n }\n @keyframes spinner1 {\n to {\n transform: rotate(360deg);\n }\n }\n .body {\n \twidth: 150px;\n \theight: 250px;\n \tborder: 5px solid #404041;\n \tbackground: #e9df72;\n \tbox-sizing: border-box;\n \tpadding: 20px;\n }\n\n body {\n \tbackground: #9e97c6;\n }\n\n .gadget {\n \twidth: 150px;\n \tposition: absolute;\n \ttop: 50%;\n \tleft: 50%;\n \ttransform: translate(-50%, -60%);\n }\n\n .button {\n \tborder-radius: 5px;\n \tborder: 4px solid #404041;\n \tmargin-top: 20px;\n \tbackground: $red;\n \tfont-family: \"Share Tech Mono\";\n \ttext-align: center;\n \tcolor: #404041;\n \tpadding: 7px;\n \tcursor: pointer;\n }\n\n .display {\n \tmargin-top: 10px;\n \theight: 80px;\n \tpadding: 5px;\n \tfont-family: \"VT323\";\n \tcolor: #404041;\n \ttext-align: center;\n }\n\n", DataAtom: vugu.VGAtom(0), Namespace: "", Attr: []vugu.VGAttribute(nil)})
var n *vugu.VGNode
n = &vugu.VGNode{Type: vugu.VGNodeType(3), Data: "div", DataAtom: vugu.VGAtom(92931), Namespace: "", Attr: []vugu.VGAttribute{vugu.VGAttribute{Namespace: "", Key: "class", Val: "gadget"}}}
vdom = n
{
parent := n
n = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n ", DataAtom: vugu.VGAtom(0), Namespace: "", Attr: []vugu.VGAttribute(nil)}
parent.AppendChild(n)
n = &vugu.VGNode{Type: vugu.VGNodeType(3), Data: "div", DataAtom: vugu.VGAtom(92931), Namespace: "", Attr: []vugu.VGAttribute{vugu.VGAttribute{Namespace: "", Key: "class", Val: "body"}}}
parent.AppendChild(n)
{
parent := n
n = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n ", DataAtom: vugu.VGAtom(0), Namespace: "", Attr: []vugu.VGAttribute(nil)}
parent.AppendChild(n)
if data.isLoading {
n = &vugu.VGNode{Type: vugu.VGNodeType(3), Data: "div", DataAtom: vugu.VGAtom(92931), Namespace: "", Attr: []vugu.VGAttribute{vugu.VGAttribute{Namespace: "", Key: "class", Val: "spinner spinner--1"}}}
parent.AppendChild(n)
}
n = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n ", DataAtom: vugu.VGAtom(0), Namespace: "", Attr: []vugu.VGAttribute(nil)}
parent.AppendChild(n)
if data.dadJoke.Joke != "" {
n = &vugu.VGNode{Type: vugu.VGNodeType(3), Data: "div", DataAtom: vugu.VGAtom(92931), Namespace: "", Attr: []vugu.VGAttribute{vugu.VGAttribute{Namespace: "", Key: "class", Val: "display"}}}
parent.AppendChild(n)
{
parent := n
n = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n ", DataAtom: vugu.VGAtom(0), Namespace: "", Attr: []vugu.VGAttribute(nil)}
parent.AppendChild(n)
n = &vugu.VGNode{Type: vugu.VGNodeType(3), Data: "span", DataAtom: vugu.VGAtom(40708), Namespace: "", Attr: []vugu.VGAttribute(nil)}
parent.AppendChild(n)
n.InnerHTML = fmt.Sprint(data.dadJoke.Joke)
n = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n ", DataAtom: vugu.VGAtom(0), Namespace: "", Attr: []vugu.VGAttribute(nil)}
parent.AppendChild(n)
}
}
n = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n ", DataAtom: vugu.VGAtom(0), Namespace: "", Attr: []vugu.VGAttribute(nil)}
parent.AppendChild(n)
}
n = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n ", DataAtom: vugu.VGAtom(0), Namespace: "", Attr: []vugu.VGAttribute(nil)}
parent.AppendChild(n)
n = &vugu.VGNode{Type: vugu.VGNodeType(3), Data: "button", DataAtom: vugu.VGAtom(102662), Namespace: "", Attr: []vugu.VGAttribute{vugu.VGAttribute{Namespace: "", Key: "class", Val: "button"}}}
parent.AppendChild(n)
// @click = { data.HandleClick(event) }
{
var i_ interface{} = data
idat_ := reflect.ValueOf(&i_).Elem().InterfaceData()
var i2_ interface{} = data.HandleClick
i2dat_ := reflect.ValueOf(&i2_).Elem().InterfaceData()
n.SetDOMEventHandler("click", vugu.DOMEventHandler{
ReceiverAndMethodHash: uint64(idat_[0]) ^ uint64(idat_[1]) ^ uint64(i2dat_[0]) ^ uint64(i2dat_[1]),
Method: reflect.ValueOf(data).MethodByName("HandleClick"),
Args: []interface{}{event},
})
}
if false {
// force compiler to check arguments for type safety
data.HandleClick(event)
}
{
parent := n
n = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "Get dad joke", DataAtom: vugu.VGAtom(0), Namespace: "", Attr: []vugu.VGAttribute(nil)}
parent.AppendChild(n)
}
n = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n", DataAtom: vugu.VGAtom(0), Namespace: "", Attr: []vugu.VGAttribute(nil)}
parent.AppendChild(n)
}
return
}
type Root struct {}
func (ct *Root) NewData(props vugu.Props) (interface{}, error) { return &RootData{}, nil }
func init() { vugu.RegisterComponentType("root", &Root{}) }