refactor: clamp\storage dry

This commit is contained in:
2026-10-09 22:09:02 +05:00
parent d58f6c90be
commit 07c6475c21
15 changed files with 68 additions and 77 deletions
+2 -5
View File
@@ -1,13 +1,10 @@
import { SvelteSet } from "svelte/reactivity";
import { safeSetItem, storage } from "./storage";
const KEY = "fav-tools";
const slugs = new SvelteSet<string>();
function storage(): Storage | null {
return typeof localStorage === "undefined" ? null : localStorage;
}
export function initFavorites(): void {
const raw = storage()?.getItem(KEY);
if (!raw) return;
@@ -31,7 +28,7 @@ export function toggleFav(slug: string): void {
} else {
slugs.add(slug);
}
storage()?.setItem(KEY, JSON.stringify([...slugs]));
safeSetItem(KEY, JSON.stringify([...slugs]));
}
/** Favorite pages from the list (order preserved). */