feat(toast-notification): clear timeout when destroyed

This commit is contained in:
Eric Liu 2019-12-25 06:20:38 -08:00
commit 7a612e60cf

View file

@ -21,14 +21,20 @@
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
let timeoutId = undefined;
let open = true; let open = true;
onMount(() => { onMount(() => {
if (timeout) { if (timeout) {
window.setTimeout(() => { timeoutId = window.setTimeout(() => {
open = false; open = false;
}, timeout); }, timeout);
} }
return () => {
window.clearTimeout(timeoutId);
timeoutId = undefined;
};
}); });
$: if (!open) { $: if (!open) {