mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 19:46:36 +00:00
Minor on-destroy code simplification.
This commit is contained in:
parent
70c754d515
commit
622538a17b
1 changed files with 6 additions and 6 deletions
|
@ -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();
|
||||
};
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue