gradio/js/timer/Index.svelte
aliabid94 2943d6d688
Add Timer component (#8505)
* chagnes

* add changeset

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* change

* add docs

* add changeset

* remove demo

* add changeset

* add changeset

* changes

* changes

* changes

* add changeset

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* Update gradio/components/timer.py

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* changes

* changes

---------

Co-authored-by: Ali Abid <aliabid94@gmail.com>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: aliabd <ali.si3luwa@gmail.com>
Co-authored-by: pngwn <hello@pngwn.io>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2024-06-28 16:53:44 -07:00

28 lines
651 B
Svelte

<script lang="ts">
import type { Gradio } from "@gradio/utils";
import { onDestroy } from "svelte";
export let gradio: Gradio<{
tick: never;
}>;
export let value = 1;
export let active = true;
let old_value: number;
let old_active: boolean;
let interval: NodeJS.Timeout;
$: if (old_value !== value || active !== old_active) {
if (interval) clearInterval(interval);
if (active) {
interval = setInterval(() => {
if (document.visibilityState === "visible") gradio.dispatch("tick");
}, value * 1000);
}
old_value = value;
old_active = active;
}
onDestroy(() => {
if (interval) clearInterval(interval);
});
</script>