-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathwade.go
102 lines (79 loc) · 1.44 KB
/
wade.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
package wade
import (
"fmt"
gourl "net/url"
"github.com/gowade/vdom"
"github.com/gowade/wade/dom"
"github.com/gowade/wade/driver"
)
type M map[string]interface{}
type AppMode int
const (
DevelopmentMode AppMode = iota
ProductionMode
)
var (
mode AppMode = DevelopmentMode
)
type Component interface{}
func ClientSide() bool {
return driver.Env() == driver.BrowserEnv
}
func DevMode() bool {
return mode == DevelopmentMode
}
func SetMode(appMode AppMode) {
mode = appMode
}
func Str(value interface{}) string {
if s, ok := value.(string); ok {
return s
}
return fmt.Sprint(value)
}
func MergeMaps(m1, m2 map[string]interface{}) map[string]interface{} {
if m1 == nil && m2 == nil {
return nil
}
m := make(map[string]interface{})
if m1 != nil {
for k, v := range m1 {
m[k] = v
}
}
if m2 != nil {
for k, v := range m2 {
m[k] = v
}
}
return m
}
func If(cond bool, v string) string {
if cond {
return v
}
return ""
}
func WrapEvt(handler func(dom.Event)) interface{} {
return dom.NewEventHandler(handler)
}
func QueryEscape(str string) string {
return gourl.QueryEscape(str)
}
func NewVNodeList(nodes ...interface{}) []vdom.VNode {
var l []vdom.VNode
for _, n := range nodes {
if n == nil {
continue
}
switch n := n.(type) {
case []vdom.VNode:
l = append(l, n...)
case *vdom.VElement, vdom.VText:
l = append(l, n.(vdom.VNode))
default:
panic("Invalid node type")
}
}
return l
}