5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 02:50:36 +08:00
wails/website/docs/reference/runtime/events.mdx
Lea Anthony 1d8f74d6d7 [v2] Docs update
(cherry picked from commit 589eb3864f)
2021-09-27 19:37:58 +10:00

52 lines
1.8 KiB
Plaintext

---
sidebar_position: 2
---
# Events
## Overview
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
Go Signature: `EventsOn(ctx context.Context, eventName string, callback func(optionalData ...interface{}))`
JS Signature: `EventsOn(eventName string, callback function(optionalData?: any))`
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.
### EventsOff
Go Signature: `EventsOff(ctx context.Context, eventName string)`
JS Signature: `EventsOff(eventName string)`
This method unregisters the listener for the given event name.
### EventsOnce
Go Signature: `EventsOnce(ctx context.Context, eventName string, callback func(optionalData ...interface{}))`
JS Signature: `EventsOnce(eventName string, callback function(optionalData?: any))`
This method sets up a listener for the given event name, but will only trigger once.
### EventsOnMultiple
Go Signature: `EventsOnMultiple(ctx context.Context, eventName string, callback func(optionalData ...interface{}), counter int)`
JS Signature: `EventsOnMultiple(eventName string, callback function(optionalData?: any), counter int)`
This method sets up a listener for the given event name, but will only trigger a maximum of `counter` times.
### EventsEmit
Go Signature: `Events(ctx context.Context, eventName string, optionalData ...interface{})`
JS Signature: `Events(ctx context, optionalData function(optionalData?: any))`
This method emits the given event. Optional data may be passed with the event. This will trigger any event listeners.