mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
37 lines
2 KiB
Text
37 lines
2 KiB
Text
---
|
|
sidebar_position: 2
|
|
---
|
|
|
|
# Events
|
|
|
|
The Wails runtime provides a unified events system, where events can be emitted or received by either Go or Javascript. Optionally, data may be passed with the events. Listeners will receive the data in the local data types.
|
|
|
|
### EventsOn
|
|
|
|
This method sets up a listener for the given event name. When an event of type `eventName` is [emitted](#EventsEmit), the callback is triggered. Any additional data sent with the emitted event will be passed to the callback.
|
|
|
|
Go: `EventsOn(ctx context.Context, eventName string, callback func(optionalData ...interface{}))`<br/> JS: `EventsOn(eventName string, callback function(optionalData?: any))`
|
|
|
|
### EventsOff
|
|
|
|
このメソッドは、指定されたイベント名のイベントリスナー設定を解除します。引数の`additionalEventNames`を使用することで、複数のリスナーを一度に解除できます。
|
|
|
|
Go: `EventsOff(ctx context.Context, eventName string, additionalEventNames ...string)`<br/> JS: `EventsOff(eventName string, ...additionalEventNames)`
|
|
|
|
### EventsOnce
|
|
|
|
This method sets up a listener for the given event name, but will only trigger once.
|
|
|
|
Go: `EventsOnce(ctx context.Context, eventName string, callback func(optionalData ...interface{}))`<br/> JS: `EventsOnce(eventName string, callback function(optionalData?: any))`
|
|
|
|
### EventsOnMultiple
|
|
|
|
This method sets up a listener for the given event name, but will only trigger a maximum of `counter` times.
|
|
|
|
Go: `EventsOnMultiple(ctx context.Context, eventName string, callback func(optionalData ...interface{}), counter int)`<br/> JS: `EventsOnMultiple(eventName string, callback function(optionalData?: any), counter int)`
|
|
|
|
### EventsEmit
|
|
|
|
This method emits the given event. Optional data may be passed with the event. This will trigger any event listeners.
|
|
|
|
Go: `EventsEmit(ctx context.Context, eventName string, optionalData ...interface{})`<br/> JS: `EventsEmit(ctx context, optionalData function(optionalData?: any))`
|