wails/website/docs/reference/runtime/events.mdx
NarciLee 4e8b705cda
fix: add missing EventsOffAll export to runtime templates (#4883)
* fix: add missing EventsOffAll export to runtime templates

The EventsOffAll function was implemented in the internal runtime
(desktop/events.js) and exported in the wrapper runtime files, but was
missing from the public runtime templates that are generated in user
projects. This caused a type mismatch where EventsOffAll was declared
in the TypeScript definition but the implementation was missing.

This commit adds the EventsOffAll export and type declaration to all
frontend framework templates:
- Common templates (generate/assets/common)
- React / React-TS
- Vue / Vue-TS
- Svelte / Svelte-TS
- Preact / Preact-TS
- Lit / Lit-TS
- Vanilla / Vanilla-TS

Fixes #4703

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* docs: add EventsOffAll to runtime events documentation

Added EventsOffAll function documentation to both English and Chinese
versions of the runtime events reference.

The function was already implemented in Go (pkg/runtime/events.go) and
JavaScript (internal/frontend/runtime/desktop/events.js), but was missing
from the public documentation.

Related to #4703

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* chore: add EventsOffAll fix to changelog

Added entry for the EventsOffAll fix to the Unreleased section
of the changelog.

Related to #4703

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* docs: translate EventsOffAll description to Chinese

Improved consistency in Chinese documentation by translating the
EventsOffAll description from English to Chinese, matching the
style of other event method descriptions.

Related to #4703

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

---------

Co-authored-by: cc <Zhuanz@MacBook-Pro.local>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
2026-01-25 13:10:24 +11:00

54 lines
2.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. It returns
a function to cancel the listener.
Go: `EventsOn(ctx context.Context, eventName string, callback func(optionalData ...interface{})) func()`<br/>
JS: `EventsOn(eventName string, callback function(optionalData?: any)): () => void`
### EventsOff
This method unregisters the listener for the given event name, optionally multiple listeners can be unregistered via `additionalEventNames`.
Go: `EventsOff(ctx context.Context, eventName string, additionalEventNames ...string)`<br/>
JS: `EventsOff(eventName string, ...additionalEventNames)`
### EventsOffAll
This method unregisters all event listeners.
Go: `EventsOffAll(ctx context.Context)`<br/>
JS: `EventsOffAll()`
### EventsOnce
This method sets up a listener for the given event name, but will only trigger once. It returns a function to cancel
the listener.
Go: `EventsOnce(ctx context.Context, eventName string, callback func(optionalData ...interface{})) func()`<br/>
JS: `EventsOnce(eventName string, callback function(optionalData?: any)): () => void`
### EventsOnMultiple
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.
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`
### 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(eventName: string, ...optionalData: any)`