import { mount, unmount } from 'svelte'; import Spinner from '../helperComponents/Spinner.svelte'; export default (node: any, loading: any) => { let app: any; const unsubscribe = loading.subscribe((isLoading: any) => { if (isLoading && !app) { app = mount(Spinner, { target: node, intro: true }); } else if (!isLoading && app) { const current = app; app = undefined; // Teardown must never break the caller. void unmount(current).catch(() => {}); } }); return { destroy() { unsubscribe(); if (app) { const current = app; app = undefined; void unmount(current).catch(() => {}); } } }; }