-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathutil.go
46 lines (38 loc) · 1.09 KB
/
util.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
package hvue
import (
"github.com/gopherjs/gopherwasm/js"
)
// NewObject is a utility function for creating a new JavaScript Object of
// type js.Value.
func NewObject() js.Value {
return js.Global().Get("Object").New()
}
// NewArray is a utility function for creating a new JS array.
func NewArray() js.Value {
return js.Global().Get("Array").New()
}
// Push appends any to the end of o, in place.
func Push(o js.Value, any interface{}) (newLength int) {
return o.Call("push", any).Int()
}
// Set is a wrapper for js{Vue.set}
func Set(o, key, value interface{}) interface{} {
js.Global().Get("Vue").Call("set", o, key, value)
return value
}
func jsCallWithVM(f func(*VM) interface{}) js.Value {
return NewCallback(
func(this js.Value, args []js.Value) interface{} {
vm := &VM{Value: this}
return f(vm)
})
}
func NewCallback(f func(this js.Value, args []js.Value) interface{}) js.Value {
return js.Global().Call("wasm_call_with_this",
js.NewCallback(func(args []js.Value) {
f(args[0], args[1:])
}))
}
func Log(args ...interface{}) {
js.Global().Get("console").Call("log", args...)
}