You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
import { writable } from "svelte/store";
interface SelectionData { path: string, hash: string, }
function createSelectionStore() { const {update, set, subscribe} = writable<SelectionData>({ 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;
|