From 622538a17b6a7b52003db38f8502f7b232112a6c Mon Sep 17 00:00:00 2001 From: Harald Brunner Date: Mon, 6 Jun 2022 21:16:05 +0200 Subject: [PATCH] Minor on-destroy code simplification. --- src/Modal/modalStore.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Modal/modalStore.js b/src/Modal/modalStore.js index 4206571a..a985b906 100644 --- a/src/Modal/modalStore.js +++ b/src/Modal/modalStore.js @@ -7,6 +7,9 @@ const stores = new Set(); /** Store for the number of open modals. */ const modalsOpen = writable(0); +const updateModalsOpen = () => + modalsOpen.set([...stores].filter((open) => get(open)).length); + /** * Adds a modal's store to the open modal tracking. * Has to be called during component initialization. @@ -17,16 +20,13 @@ const modalsOpen = writable(0); export const trackModal = (openStore) => onMount(() => { stores.add(openStore); - - const unsubscribe = openStore.subscribe(() => - modalsOpen.set([...stores].filter((open) => get(open)).length) - ); + const unsubscribe = openStore.subscribe(updateModalsOpen); return () => { unsubscribe(); - if (get(openStore)) modalsOpen.update((count) => count - 1); - stores.delete(openStore); + + updateModalsOpen(); }; });