This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { writable, type Updater, type Writable } from 'svelte/store'; | |
/** | |
* Create a writable store that persists to sessionStorage or localStorage. | |
* | |
* Usage example: | |
* export const colorScheme = createPersistentWritable<'system' | 'dark' | 'light'>({ storageId: 'color-scheme', useLocalStorage: true }, 'dark'); | |
*/ | |
export function createPersistentWritable<T>( | |
{ storageId, useLocalStorage }: { storageId: string; useLocalStorage?: boolean }, |