mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 03:47:37 +03:00
chore(docs): simplify event system documentation
This commit is contained in:
parent
4866404f04
commit
f68603aee4
5
.changes/simplify-window-label-types.md
Normal file
5
.changes/simplify-window-label-types.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"api": patch
|
||||
---
|
||||
|
||||
Change `WindowLabel` type to `string`.
|
File diff suppressed because one or more lines are too long
@ -36,11 +36,10 @@ emit('click', {
|
||||
Window-specific events are exposed on the `window` module.
|
||||
|
||||
```ts
|
||||
import { getCurrent, WebviewWindow } from '@tauri-apps/api/window'
|
||||
import { appWindow, WebviewWindow } from '@tauri-apps/api/window'
|
||||
|
||||
// emit an event that are only visible to the current window
|
||||
const current = getCurrent()
|
||||
current.emit('event', { message: 'Tauri is awesome!' })
|
||||
appWindow.emit('event', { message: 'Tauri is awesome!' })
|
||||
|
||||
// create a new webview window and emit an event only to that window
|
||||
const webview = new WebviewWindow('window')
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,10 +1,10 @@
|
||||
<script>
|
||||
import { appWindow, WebviewWindow, LogicalSize, LogicalPosition, UserAttentionType, getCurrent, PhysicalSize, PhysicalPosition } from "@tauri-apps/api/window";
|
||||
import { appWindow, WebviewWindow, LogicalSize, LogicalPosition, UserAttentionType, PhysicalSize, PhysicalPosition } from "@tauri-apps/api/window";
|
||||
import { open as openDialog } from "@tauri-apps/api/dialog";
|
||||
import { open } from "@tauri-apps/api/shell";
|
||||
|
||||
window.UserAttentionType = UserAttentionType;
|
||||
let selectedWindow = getCurrent().label;
|
||||
let selectedWindow = appWindow.label;
|
||||
const windowMap = {
|
||||
[selectedWindow]: appWindow
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ function getAll(): WebviewWindow[] {
|
||||
// events that are emitted right here instead of by the created webview
|
||||
const localTauriEvents = ['tauri://created', 'tauri://error']
|
||||
/** @ignore */
|
||||
export type WindowLabel = string | null | undefined
|
||||
export type WindowLabel = string
|
||||
/**
|
||||
* A webview window handle allows emitting and listening to events from the backend that are tied to the window.
|
||||
*/
|
||||
@ -230,8 +230,8 @@ class WebviewWindowHandle {
|
||||
/** Local event listeners. */
|
||||
listeners: { [key: string]: Array<EventCallback<any>> }
|
||||
|
||||
constructor(label: WindowLabel) {
|
||||
this.label = label
|
||||
constructor(label: WindowLabel | null | undefined) {
|
||||
this.label = label ?? window.__TAURI__.__currentWindow.label
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
this.listeners = Object.create(null)
|
||||
}
|
||||
@ -1092,7 +1092,10 @@ class WindowManager extends WebviewWindowHandle {
|
||||
* ```
|
||||
*/
|
||||
class WebviewWindow extends WindowManager {
|
||||
constructor(label: WindowLabel, options: WindowOptions = {}) {
|
||||
constructor(
|
||||
label: WindowLabel | null | undefined,
|
||||
options: WindowOptions = {}
|
||||
) {
|
||||
super(label)
|
||||
// @ts-expect-error
|
||||
if (!options?.skip) {
|
||||
|
Loading…
Reference in New Issue
Block a user