Files

48 lines
2.1 KiB
Plaintext
Raw Permalink Normal View History

2022-08-27 20:17:15 +10:00
---
sidebar_position: 2
---
# Events
2022-12-30 07:38:22 +11:00
The Wails runtime provides a unified events system, where events can be emitted or received by either Go or JavaScript.
2022-09-18 11:00:39 +10:00
Optionally, data may be passed with the events. Listeners will receive the data in the local data types.
2022-08-27 20:17:15 +10:00
### EventsOn
2022-09-18 11:00:39 +10:00
This method sets up a listener for the given event name. When an event of type `eventName` is [emitted](#EventsEmit),
2022-11-09 22:26:22 +11:00
the callback is triggered. Any additional data sent with the emitted event will be passed to the callback. It returns
a function to cancel the listener.
2022-08-27 20:17:15 +10:00
2022-11-09 22:26:22 +11:00
Go: `EventsOn(ctx context.Context, eventName string, callback func(optionalData ...interface{})) func()`<br/>
JS: `EventsOn(eventName string, callback function(optionalData?: any)): () => void`
2022-08-27 20:17:15 +10:00
### EventsOff
2022-09-12 21:56:43 +10:00
This method unregisters the listener for the given event name, optionally multiple listeneres can be unregistered via `additionalEventNames`.
2022-08-27 20:17:15 +10:00
2022-09-18 11:00:39 +10:00
Go: `EventsOff(ctx context.Context, eventName string, additionalEventNames ...string)`<br/>
JS: `EventsOff(eventName string, ...additionalEventNames)`
2022-08-27 20:17:15 +10:00
### EventsOnce
2022-11-09 22:26:22 +11:00
This method sets up a listener for the given event name, but will only trigger once. It returns a function to cancel
the listener.
2022-08-27 20:17:15 +10:00
2022-11-09 22:26:22 +11:00
Go: `EventsOnce(ctx context.Context, eventName string, callback func(optionalData ...interface{})) func()`<br/>
JS: `EventsOnce(eventName string, callback function(optionalData?: any)): () => void`
2022-08-27 20:17:15 +10:00
### EventsOnMultiple
2022-11-09 22:26:22 +11:00
This method sets up a listener for the given event name, but will only trigger a maximum of `counter` times. It returns
a function to cancel the listener.
2022-08-27 20:17:15 +10:00
2022-11-09 22:26:22 +11:00
Go: `EventsOnMultiple(ctx context.Context, eventName string, callback func(optionalData ...interface{}), counter int) func()`<br/>
JS: `EventsOnMultiple(eventName string, callback function(optionalData?: any), counter int): () => void`
2022-08-27 20:17:15 +10:00
### EventsEmit
This method emits the given event. Optional data may be passed with the event. This will trigger any event listeners.
2022-09-18 11:00:39 +10:00
Go: `EventsEmit(ctx context.Context, eventName string, optionalData ...interface{})`<br/>
2023-01-16 10:59:58 +01:00
JS: `EventsEmit(eventName: string, ...optionalData: any)`