# svelte-state-store

> A [Svelte writable store](https://svelte.dev/docs/svelte-store#writable) that allows immediate access to the current state via a `value` getter. This avoids the need to use the less efficient `get(store)` and to access the current store value without havi

Latest version **0.0.3** (published 2024-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install svelte-state-store
pnpm add svelte-state-store
yarn add svelte-state-store
bun add svelte-state-store
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2024-04-27 |
| First published | 2023-11-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 3.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Simon Green |
| Maintainers | captaincodeman |

## Links

- npm: https://www.npmjs.com/package/svelte-state-store
- Repository: https://github.com/captaincodeman/svelte-state-store
- Homepage: https://captaincodeman.github.io/svelte-state-store/
- Issues: https://github.com/captaincodeman/svelte-state-store/issues
- npm.io page: https://npm.io/package/svelte-state-store

## Recent versions

- 0.0.3 (latest) — 2024-04-27
- 0.0.2 — 2023-11-07
- 0.0.1 — 2023-11-06

## README

# svelte-state-store

A [Svelte writable store](https://svelte.dev/docs/svelte-store#writable) that allows immediate access to the current state via a `value` getter.
This avoids the need to use the less efficient `get(store)` and to access the current store value without having to setup a subscription which can sometimes be awkward.

It can be useful where you need a store value but it isn't a dependency that would need to trigger an update or you would otherwise need to `get` the value inside a tight loop (e.g. a mouseover handler checking for the pointer being over objects that are within a store, to set the highlighted one). In certain situations it can help create simpler more efficient code.

## Usage

Install using your package-manager of choice, e.g.

    pnpm i -D svelte-state-store

Import and use just as you would a regular `writable` store:

```ts
import { state } from 'svelte-state-store';

export const my_store = state(123);
```

You can now use the store as a regular `writable` store, subscribing to it for updates, and using it with `derived` stores, but you can also access the current value outside of a subscription using:

```ts
console.log(my_store.value); // 123
```

You can pass a `StartStopNotifier` to the store, just as with a regular Svelte `writable` store.

If you need to define a type for your store, use `State` where you would have used `Writable`:

```ts
import type { Writable } from 'svelte/store`

function that_uses_store(store: Writable<StoreValue>) { }
```

becomes ...

```ts
import type { State } from 'svelte-state-store`

function that_uses_store(store: State<StoreValue>) { }
```

---
_Source: https://npm.io/package/svelte-state-store · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
