chore(docs): simplify event system documentation

This commit is contained in:
Lucas Nogueira 2021-09-27 13:07:05 -03:00
parent 4866404f04
commit f68603aee4
No known key found for this signature in database
GPG Key ID: 2714B66BCFB01F7F
7 changed files with 20 additions and 13 deletions

View File

@ -0,0 +1,5 @@
---
"api": patch
---
Change `WindowLabel` type to `string`.

File diff suppressed because one or more lines are too long

View File

@ -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

View File

@ -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
}

View File

@ -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) {