🪖 Moves persistent store to svelte-utilities

This commit is contained in:
Rune Harlyk
2024-02-22 23:51:21 +01:00
parent edbe907fa7
commit 5e789fce38
3 changed files with 3 additions and 2 deletions
+1
View File
@@ -1,3 +1,4 @@
export * from './result'
export * from './string-utilities'
export * from './svelte-utilities'
export * from './math-utilities'
+13
View File
@@ -0,0 +1,13 @@
import { writable } from "svelte/store";
export const persistentStore = (key:string, initialValue:any) => {
const savedValue = JSON.parse(localStorage.getItem(key) as string);
const data = savedValue !== null ? savedValue : initialValue;
const store = writable(data);
store.subscribe(value => {
localStorage.setItem(key, JSON.stringify(value));
});
return store;
}