mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
refactor: clamp\storage dry
This commit is contained in:
@@ -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). */
|
||||
|
||||
Reference in New Issue
Block a user