Superpowered to do lists. No signup required.

try catch error if local storage is undefiend when parsed

+10 -4
+9 -3
src/lib/stores.svelte.ts
··· 3 3 const storage = browser_exists ? localStorage : null; 4 4 5 5 // Generalized Local Storage 6 - function persisted<T>(key: string, initial_value: T) { 7 - let value : T = $state(initial_value); 6 + function persisted<T>(key: string, default_value: T) { 7 + let value : T = $state(default_value); 8 8 9 9 const initial_local = storage?.getItem(key); 10 10 if (initial_local) { 11 - value = JSON.parse(initial_local).value as T; 11 + try { 12 + value = JSON.parse(initial_local).value as T; 13 + if (!value) { update(default_value); } 14 + } 15 + catch (e) { 16 + update(default_value); 17 + } 12 18 } 13 19 14 20 function update(new_value : T) {
+1 -1
src/routes/+page.svelte
··· 4 4 $effect(() => console.log(todo_list)); 5 5 6 6 // TODO: get better ID management 7 - let id = 0; 7 + let id = $state(0); 8 8 let description = $state(""); 9 9 10 10 function randomizeId() {