blob: a253ae9d0c804940387f2b90c22056810d3348d8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import { get } from "svelte/store";
import { writable_persistent } from "./persistent-store";
const state = writable_persistent<any>({
initialState: {},
name: "global-state"
});
export type GlobalStateKeys = "isLoggedIn" | "showEmailValidatedAlertWhenLoggedIn" | "all";
export function fgs(key: GlobalStateKeys): any {
const value = get(state);
if (key === "all") return value;
return value[key];
}
export function sgs(key: GlobalStateKeys, value: any) {
if (key === "all") throw new Error("Not allowed to set global state key: all");
const stateValue = get(state);
stateValue[key] = JSON.stringify(value)
state.set(stateValue);
}
|