mirror of
https://github.com/golang/go.git
synced 2025-11-02 09:40:56 +00:00
syscall/js: rename Callback.Close to Release and expose Callback.Value
This makes Callback more in line with TypedArray. The name "Release" is better than "Close" because the function does not implement io.Closer. Change-Id: I23829a14b1c969ceb04608afd9505fd5b4b0df2e Reviewed-on: https://go-review.googlesource.com/121216 Run-TryBot: Richard Musiol <neelance@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
257d6c48e0
commit
c07f2b0099
4 changed files with 21 additions and 19 deletions
|
|
@ -214,7 +214,7 @@ func TestCallback(t *testing.T) {
|
|||
}
|
||||
c <- struct{}{}
|
||||
})
|
||||
defer cb.Close()
|
||||
defer cb.Release()
|
||||
js.Global().Call("setTimeout", cb, 0, 42)
|
||||
<-c
|
||||
}
|
||||
|
|
@ -234,10 +234,10 @@ func TestEventCallback(t *testing.T) {
|
|||
cb := js.NewEventCallback(flags, func(event js.Value) {
|
||||
c <- struct{}{}
|
||||
})
|
||||
defer cb.Close()
|
||||
defer cb.Release()
|
||||
|
||||
event := js.Global().Call("eval", fmt.Sprintf("({ called: false, %s: function() { this.called = true; } })", name))
|
||||
js.ValueOf(cb).Invoke(event)
|
||||
cb.Invoke(event)
|
||||
if !event.Get("called").Bool() {
|
||||
t.Errorf("%s not called", name)
|
||||
}
|
||||
|
|
@ -250,7 +250,7 @@ func ExampleNewCallback() {
|
|||
var cb js.Callback
|
||||
cb = js.NewCallback(func(args []js.Value) {
|
||||
fmt.Println("button clicked")
|
||||
cb.Close() // close the callback if the button will not be clicked again
|
||||
cb.Release() // release the callback if the button will not be clicked again
|
||||
})
|
||||
js.Global().Get("document").Call("getElementById", "myButton").Call("addEventListener", "click", cb)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue