event
The event system allows you to emit events to the backend and listen to events from it.
This package is also accessible with window.__TAURI__.event
when app.withGlobalTauri
in tauri.conf.json
is set to true
.
Enumerations
TauriEvent
Since
1.1.0
Enumeration Members
DRAG_DROP
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L62
DRAG_ENTER
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L60
DRAG_LEAVE
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L63
DRAG_OVER
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L61
WEBVIEW_CREATED
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L59
WINDOW_BLUR
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L55
WINDOW_CLOSE_REQUESTED
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L52
WINDOW_CREATED
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L58
WINDOW_DESTROYED
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L53
WINDOW_FOCUS
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L54
WINDOW_MOVED
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L51
WINDOW_RESIZED
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L50
WINDOW_SCALE_FACTOR_CHANGED
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L56
WINDOW_THEME_CHANGED
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L57
Interfaces
Event<T>
Type Parameters
Type Parameter |
---|
T |
Properties
Property | Type | Description | Defined in |
---|---|---|---|
event | EventName | Event name | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L24 |
id | number | Event identifier used to unlisten | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L26 |
payload | T | Event payload | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L28 |
Options
Properties
Property | Type | Description | Defined in |
---|---|---|---|
target? | string | EventTarget | The event target to listen to, defaults to { kind: 'Any' } , see EventTarget. If a string is provided, EventTarget.AnyLabel is used. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L43 |
Type Aliases
EventCallback()<T>
Type Parameters
Type Parameter |
---|
T |
Parameters
Parameter | Type |
---|---|
event | Event <T > |
Returns
void
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L31
EventName
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L35
EventTarget
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L14
UnlistenFn()
Returns
void
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L33
Functions
emit()
Emits an event to all targets.
Parameters
Parameter | Type | Description |
---|---|---|
event | string | Event name. Must include only alphanumeric characters, - , / , : and _ . |
payload ? | unknown | Event payload. |
Returns
Promise
<void
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L177
emitTo()
Emits an event to all targets matching the given target.
Parameters
Parameter | Type | Description |
---|---|---|
target | string | EventTarget | Label of the target Window/Webview/WebviewWindow or raw EventTarget object. |
event | string | Event name. Must include only alphanumeric characters, - , / , : and _ . |
payload ? | unknown | Event payload. |
Returns
Promise
<void
>
Example
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L199
listen()
Listen to an emitted event to any target.
Type Parameters
Type Parameter |
---|
T |
Parameters
Parameter | Type | Description |
---|---|---|
event | EventName | Event name. Must include only alphanumeric characters, - , / , : and _ . |
handler | EventCallback <T > | Event handler callback. |
options ? | Options | Event listening options. |
Returns
A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L103
once()
Listens once to an emitted event to any target.
Type Parameters
Type Parameter |
---|
T |
Parameters
Parameter | Type | Description |
---|---|---|
event | EventName | Event name. Must include only alphanumeric characters, - , / , : and _ . |
handler | EventCallback <T > | Event handler callback. |
options ? | Options | Event listening options. |
Returns
A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/event.ts#L147
© 2024 Tauri Contributors. CC-BY / MIT