frontend / 6.0.0-dev.5 /timer /Index.svelte
gradio-pr-bot's picture
Upload folder using huggingface_hub
dc3f773 verified
raw
history blame
622 Bytes
<script lang="ts">
import { onDestroy } from "svelte";
import type { TimerProps, TimerEvents } from "./types";
import { Gradio } from "@gradio/utils";
const props = $props();
const gradio = new Gradio<TimerEvents, TimerProps>(props);
let interval: NodeJS.Timeout | undefined = undefined;
$effect(() => {
if (interval) clearInterval(interval);
if (gradio.props.active) {
interval = setInterval(() => {
if (document.visibilityState === "visible") {
gradio.dispatch("tick");
}
}, gradio.props.value * 1000);
}
});
onDestroy(() => {
if (interval) clearInterval(interval);
});
</script>