An open API service indexing awesome lists of open source software.

https://github.com/svelterun/store

Persisted version of svelte/store.
https://github.com/svelterun/store

data state state-management store svelte svelte-store sveltekit svelterun typescript

Last synced: 6 months ago
JSON representation

Persisted version of svelte/store.

Awesome Lists containing this project

README

          


@svelterun/store


Persisted version of Svelte's writable store.


## Installation

```bash
pnpm add @svelterun/store
```

```bash
yarn add @svelterun/store
```

```bash
npm i -D @svelterun/store
```

## Usage

### `./stores.js`

```javascript
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%',
// ...
})
```

### `./App.svelte`

```javascript
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
```

## License

MIT © [Svelte.run](https://github.com/svelterun), [Nicholas Berlette](https://github.com/nberlette)