···3const storage = browser_exists ? localStorage : null;
45// Generalized Local Storage
6-function persisted<T>(key: string, initial_value: T) {
7- let value : T = $state(initial_value);
89 const initial_local = storage?.getItem(key);
10 if (initial_local) {
11- value = JSON.parse(initial_local).value as T;
00000012 }
1314 function update(new_value : T) {
···3const storage = browser_exists ? localStorage : null;
45// Generalized Local Storage
6+function persisted<T>(key: string, default_value: T) {
7+ let value : T = $state(default_value);
89 const initial_local = storage?.getItem(key);
10 if (initial_local) {
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+ }
18 }
1920 function update(new_value : T) {
+1-1
src/routes/+page.svelte
···4 $effect(() => console.log(todo_list));
56 // TODO: get better ID management
7- let id = 0;
8 let description = $state("");
910 function randomizeId() {
···4 $effect(() => console.log(todo_list));
56 // TODO: get better ID management
7+ let id = $state(0);
8 let description = $state("");
910 function randomizeId() {