import { writable } from 'svelte/store'; import type { Writable } from 'svelte/store'; import type { LoadingState } from '$lib/types'; const defaultLoading: LoadingState = { loading: false }; export const loadingStateStore: Writable = writable(defaultLoading); export const initLoading = async (message: string, task: Promise): Promise => { loadingStateStore.set({ loading: true, message }); const result: T = await task; loadingStateStore.set({ loading: false }); return result; };