aboutsummaryrefslogtreecommitdiffstats
path: root/code/app/src/help
diff options
context:
space:
mode:
Diffstat (limited to 'code/app/src/help')
-rw-r--r--code/app/src/help/persistent-store.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/code/app/src/help/persistent-store.ts b/code/app/src/help/persistent-store.ts
index f2c14c9..6a54282 100644
--- a/code/app/src/help/persistent-store.ts
+++ b/code/app/src/help/persistent-store.ts
@@ -1,3 +1,4 @@
+import {browser} from "$app/environment";
import {writable as _writable, readable as _readable} from "svelte/store";
import type {Writable, Readable, StartStopNotifier} from "svelte/store";
@@ -28,6 +29,7 @@ interface ReadableStore<T> {
}
function get_store(type: StoreType): Storage {
+ if (!browser) return undefined;
switch (type) {
case StoreType.SESSION:
return window.sessionStorage;
@@ -48,6 +50,7 @@ function prepared_store_value(value: any): string {
function get_store_value<T>(options: WritableStore<T> | ReadableStore<T>): any {
try {
const storage = get_store(options.options.store);
+ if (!storage) return;
const value = storage.getItem(options.name);
if (!value) return false;
return JSON.parse(value);
@@ -64,6 +67,7 @@ function hydrate<T>(store: Writable<T>, options: WritableStore<T> | ReadableStor
function subscribe<T>(store: Writable<T> | Readable<T>, options: WritableStore<T> | ReadableStore<T>): void {
const storage = get_store(options.options.store);
+ if (!storage) return;
if (!store.subscribe) return;
store.subscribe((state: any) => {
storage.setItem(options.name, prepared_store_value(state));
@@ -71,6 +75,10 @@ function subscribe<T>(store: Writable<T> | Readable<T>, options: WritableStore<T
}
function writable_persistent<T>(options: WritableStore<T>): Writable<T> {
+ if (!browser) {
+ console.warn("Persistent store is only available in the browser");
+ return;
+ }
if (options.options === undefined) options.options = default_store_options;
console.log("Creating writable store with options: ", options);
const store = _writable<T>(options.initialState);
@@ -80,6 +88,10 @@ function writable_persistent<T>(options: WritableStore<T>): Writable<T> {
}
function readable_persistent<T>(options: ReadableStore<T>): Readable<T> {
+ if (!browser) {
+ console.warn("Persistent store is only available in the browser");
+ return;
+ }
if (options.options === undefined) options.options = default_store_options;
console.log("Creating readable store with options: ", options);
const store = _readable<T>(options.initialState, options.callback);