-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcomputed.go
55 lines (52 loc) · 1.91 KB
/
computed.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
package hvue
import (
"github.com/gopherjs/gopherwasm/js"
)
// Computed defines name as a computed property. Note that name *must not* be
// set in data for this to work. It's probably best if it's not even a slot
// in the struct. Only access it via vm.Get. You could also create an
// accessor; see the 04-computed-with-setter example.
//
// Computed functions require synchronous functions that can return values to
// Vue. Go/wasm cannot support either of those things just yet. So currently
// this function just panics.
//
// Use a watcher instead.
func Computed(name string, f func(vm *VM) interface{}) ComponentOption {
panic("Computed not supported")
// return func(c *Config) {
// if c.Computed() == js.Undefined() {
// c.SetComputed(NewObject())
// }
// c.Computed().Set(name, jsCallWithVM(f))
// }
}
// ComputedWithGetSet defines name as a computed property with explicit get &
// set. Note that name *must not* be set in data for this to work. It's
// probably best if it's not even a slot in the struct. Only access it via
// vm.Get/Set. You could create an accessor; see the 04-computed-with-setter
// example.
//
// Computed functions require synchronous functions that can return values to
// Vue. Go/wasm cannot support either of those things just yet. So currently
// this function just panics.
//
// Use a watcher instead.
func ComputedWithGetSet(name string, get func(vm *VM) interface{}, set func(vm *VM, newValue js.Value)) ComponentOption {
panic("ComputedWithGetSet not supported")
// return func(c *Config) {
// if c.Computed() == js.Undefined() {
// c.SetComputed(NewObject())
// }
// c.Computed().Set(name,
// map[string]interface{}{
// "get": jsCallWithVM(get),
// "set": NewCallback(
// func(this js.Value, args []js.Value) interface{} {
// vm := &VM{Value: this}
// set(vm, args[0])
// return nil
// })})
// c.Setters().Set(name, true)
// }
}