mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
fix: clear timeout in onMount return function
This commit is contained in:
parent
bd6bd15c79
commit
fff54a19eb
3 changed files with 23 additions and 21 deletions
|
@ -4,27 +4,28 @@
|
|||
export let iconDescription = undefined;
|
||||
export let successDelay = 1500;
|
||||
|
||||
import { createEventDispatcher, afterUpdate, onDestroy } from "svelte";
|
||||
import { createEventDispatcher, afterUpdate, onMount } from "svelte";
|
||||
import CheckmarkFilled16 from "carbon-icons-svelte/lib/CheckmarkFilled16";
|
||||
import Error20 from "carbon-icons-svelte/lib/Error20";
|
||||
import { Loading } from "../Loading";
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
$: timeoutId = undefined;
|
||||
let timeout = undefined;
|
||||
|
||||
onMount(() => {
|
||||
return () => {
|
||||
clearTimeout(timeout);
|
||||
};
|
||||
});
|
||||
|
||||
afterUpdate(() => {
|
||||
if (status === "finished") {
|
||||
timeoutId = window.setTimeout(() => {
|
||||
timeout = setTimeout(() => {
|
||||
dispatch("success");
|
||||
}, successDelay);
|
||||
}
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
window.clearTimeout(timeoutId);
|
||||
timeoutId = undefined;
|
||||
});
|
||||
</script>
|
||||
|
||||
<div
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue