pnpm add @svelterun/store
yarn add @svelterun/store
npm i -D @svelterun/store
import { writable } from '@svelterun/store'
/**
* @param {string} key - localStorage key
* @param {*} value - the store's initial value
* @returns {import('svelte/store').Writable}
*/
export const preferences = writable('preferences', {
theme: 'dark',
pane: '50%',
// ...
})
import { get } from 'svelte/store'
import { preferences } from './stores'
// subscribe to changes
preferences.subscribe(value => console.log('preferences:\n', value))
// update value
preferences.update(current => ({...current, theme: 'light'}))
// set value
preferences.set(value)
// read value
get(preferences)
// read value with auto subscription
$preferences
MIT © Svelte.run, Nicholas Berlette