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();
let timeoutId = undefined;
let open = true;
onMount(() => {
if (timeout) {
window.setTimeout(() => {
timeoutId = window.setTimeout(() => {
open = false;
}, timeout);
}
return () => {
window.clearTimeout(timeoutId);
timeoutId = undefined;
};
});
$: if (!open) {