fix(example): unlisten to event on tab change in api example (#1436)

* unlisten to event on tab change in api example

* rewrite

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
chip 2021-04-06 15:51:15 -07:00 committed by GitHub
parent f4ae2d2487
commit 9ce0569f17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 5 deletions

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,19 @@
<script>
import { listen, emit } from "@tauri-apps/api/event";
import { invoke } from "@tauri-apps/api/tauri";
import { onMount, onDestroy } from "svelte";
export let onMessage;
let unlisten;
listen("rust-event", onMessage)
onMount(async () => {
unlisten = await listen("rust-event", onMessage)
})
onDestroy(() => {
if (unlisten) {
unlisten()
}
})
function log() {
invoke("log_operation", {