import { writable } from "svelte/store"; interface SelectionData { path: string, hash: string, } function createSelectionStore() { const {update, set, subscribe} = writable({ path: window.location.pathname, hash: window.location.hash.slice(1), }); return { subscribe, refresh() { set({ path: window.location.pathname, hash: window.location.hash.slice(1), }); }, change(key: keyof(SelectionData), value: string) { if (key === "hash") { window.location.hash = "#" + value; } update(d => ({...d, [key]: value})); }, } } const selectionStore = createSelectionStore(); window.addEventListener("hashchange", () => { selectionStore.refresh(); }); export default selectionStore;