From e55c763986b694e6f5282ca1f2aa83e544f95df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Sat, 21 Dec 2024 17:37:30 +0100 Subject: [PATCH] Fixed docs for svelte/store not being rendered --- packages/svelte/types/index.d.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index d422abebbc0f..5d36ff818550 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -2148,10 +2148,42 @@ declare module 'svelte/store' { */ update(this: void, updater: Updater): void; } + + /** + * Create a store from a function that returns state, and (to make a writable store), an + * optional second function that sets state. + * + * ```ts + * import { toStore } from 'svelte/store'; + * + * let count = $state(0); + * + * const store = toStore(() => count, (v) => (count = v)); + * ``` + */ export function toStore(get: () => V, set: (v: V) => void): Writable; export function toStore(get: () => V): Readable; + /** + * Convert a store to an object with a reactive `current` property. If `store` + * is a readable store, `current` will be a readonly property. + * + * ```ts + * import { fromStore, get, writable } from 'svelte/store'; + * + * const store = writable(0); + * + * const count = fromStore(store); + * + * count.current; // 0; + * store.set(1); + * count.current; // 1 + * + * count.current += 1; + * get(store); // 2 + * ``` + */ export function fromStore(store: Writable): { current: V; };