-
Notifications
You must be signed in to change notification settings - Fork 5
proposal: support wrapping existing native objects #25
Comments
I think your suggestion makes sense. I'm happy that you're trying to use GopherWasm at Vecty :-)
My concern is the name: I'm worried the possibility that |
I considered this, too, but I think it is unlikely as there was some prior discussion about adding a I think it could be a good choice of naming here because this function would likely often be used when performing interoperability. |
Thank you! After reading the comment, I came up with the same concern: what will
I don't know other examples. Could you show me one? |
With With
Basically, I imagine this will be used often in conjunction with event handling in specific. For example in Vecty any time you define an event handler you will call this once or twice: event.Input(func(e *vecty.Event) {
p.Input = gopherwasm.Wrap(e.Target).Get("value").String()
gopherwasm.Wrap(e.Value).Call("preventDefault")
vecty.Rerender(p)
}), But if the name is complex, long, hard to type, etc. it becomes much more verbose: event.Input(func(e *vecty.Event) {
p.Input = gopherwasm.ToGopherWasmValue(e.Target).Get("value").String()
gopherwasm.ToGopherWasmValue(e.Value).Call("preventDefault")
vecty.Rerender(p)
}), |
|
I meant that I was wondering if there are other libraries that use a function named Thank you for your example, I think that makes sense. |
I found several examples like https://godoc.org/github.com/pkg/errors#Wrap OK, I'm now convinced to add |
Ah, I see, I misunderstood. Yes, I will create a PR in the near future (but possibly not this weekend). |
https://tip.golang.org/doc/go1.12#syscall/js As Go 1.12 tries to introduce |
Hmm, interesting. I was actually thinking // From creates a gopherwasm Value from a syscall/js.Value or *gopherjs/js.Object.
func From(v js.Value) Value |
Yet another suggestion: would it work if we extend |
If you are making use of a library which only gives you an underlying
*gopherjs/js.Object
(GopherJS) orsyscall/js.Value
(WebAssembly) object, it is impossible to use this library with that object.This is unfortunate because it makes interoperability hard: when you are given one of these underlying objects, you must use those APIs independently rather than being able to make use of this generic library. It means that in order to use this library, you must effectively switch completely to this library first.
The primary reason I bring this up is because Vecty will not expose this library but rather only the native object type, which means users of Vecty will not be able to use this package. I would like them to be able to.
I thus propose a way to wrap an existing native object and get back a
gopherwasm/js.Value
. This would be done by a function whose type signature changes based on a build tag:Under GopherJS:
And under WebAssembly:
The text was updated successfully, but these errors were encountered: