anastasis-webui: prevent webpack warning

This commit is contained in:
Florian Dold 2021-10-15 09:44:41 +02:00
parent f2492cac6d
commit 684b1efaaa
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 15 additions and 6 deletions

View File

@ -235,10 +235,23 @@ export interface AnastasisReducerApi {
runTransaction(f: (h: ReducerTransactionHandle) => Promise<void>): void; runTransaction(f: (h: ReducerTransactionHandle) => Promise<void>): void;
} }
function storageGet(key: string): string | null {
if (typeof localStorage === "object") {
return localStorage.getItem(key);
}
return null;
}
function storageSet(key: string, value: any): void {
if (typeof localStorage === "object") {
return localStorage.setItem(key, value);
}
}
function restoreState(): any { function restoreState(): any {
let state: any; let state: any;
try { try {
let s = localStorage.getItem("anastasisReducerState"); let s = storageGet("anastasisReducerState");
if (s === "undefined") { if (s === "undefined") {
state = undefined; state = undefined;
} else if (s) { } else if (s) {
@ -261,7 +274,7 @@ export function useAnastasisReducer(): AnastasisReducerApi {
const setAnastasisState = (newState: AnastasisState) => { const setAnastasisState = (newState: AnastasisState) => {
try { try {
localStorage.setItem( storageSet(
"anastasisReducerState", "anastasisReducerState",
JSON.stringify(newState.reducerState), JSON.stringify(newState.reducerState),
); );

View File

@ -1,4 +0,0 @@
// import { getFiles, setupPrecaching, setupRouting } from 'preact-cli/sw/';
// setupRouting();
// setupPrecaching(getFiles());