Skip to content

Commit

Permalink
Fixed docs for svelte/store not being rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Dec 21, 2024
1 parent 999b92d commit 8334e32
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 44 deletions.
44 changes: 22 additions & 22 deletions packages/svelte/src/store/index-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import { createSubscriber } from '../reactivity/create-subscriber.js';
export { derived, get, readable, readonly, writable } from './shared/index.js';

/**
* 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));
* ```
* @template V
* @overload
* @param {() => V} get
Expand All @@ -23,16 +33,6 @@ export { derived, get, readable, readonly, writable } from './shared/index.js';
* @returns {Readable<V>}
*/
/**
* 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));
* ```
* @template V
* @param {() => V} get
* @param {(v: V) => void} [set]
Expand Down Expand Up @@ -71,18 +71,6 @@ export function toStore(get, set) {
};
}

/**
* @template V
* @overload
* @param {Writable<V>} store
* @returns {{ current: V }}
*/
/**
* @template V
* @overload
* @param {Readable<V>} store
* @returns {{ readonly current: V }}
*/
/**
* Convert a store to an object with a reactive `current` property. If `store`
* is a readable store, `current` will be a readonly property.
Expand All @@ -101,6 +89,18 @@ export function toStore(get, set) {
* count.current += 1;
* get(store); // 2
* ```
* @template V
* @overload
* @param {Writable<V>} store
* @returns {{ current: V }}
*/
/**
* @template V
* @overload
* @param {Readable<V>} store
* @returns {{ readonly current: V }}
*/
/**
* @template V
* @param {Writable<V> | Readable<V>} store
*/
Expand Down
44 changes: 22 additions & 22 deletions packages/svelte/src/store/index-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import { get, writable } from './shared/index.js';
export { derived, get, readable, readonly, writable } from './shared/index.js';

/**
* 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));
* ```
* @template V
* @overload
* @param {() => V} get
Expand All @@ -17,16 +27,6 @@ export { derived, get, readable, readonly, writable } from './shared/index.js';
* @returns {Readable<V>}
*/
/**
* 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));
* ```
* @template V
* @param {() => V} get
* @param {(v: V) => void} [set]
Expand All @@ -48,18 +48,6 @@ export function toStore(get, set) {
};
}

/**
* @template V
* @overload
* @param {Writable<V>} store
* @returns {{ current: V }}
*/
/**
* @template V
* @overload
* @param {Readable<V>} store
* @returns {{ readonly current: V }}
*/
/**
* Convert a store to an object with a reactive `current` property. If `store`
* is a readable store, `current` will be a readonly property.
Expand All @@ -78,6 +66,18 @@ export function toStore(get, set) {
* count.current += 1;
* get(store); // 2
* ```
* @template V
* @overload
* @param {Writable<V>} store
* @returns {{ current: V }}
*/
/**
* @template V
* @overload
* @param {Readable<V>} store
* @returns {{ readonly current: V }}
*/
/**
* @template V
* @param {Writable<V> | Readable<V>} store
*/
Expand Down
32 changes: 32 additions & 0 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2148,10 +2148,42 @@ declare module 'svelte/store' {
*/
update(this: void, updater: Updater<T>): 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<V>(get: () => V, set: (v: V) => void): Writable<V>;

export function toStore<V>(get: () => V): Readable<V>;

/**
* 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<V>(store: Writable<V>): {
current: V;
};
Expand Down

0 comments on commit 8334e32

Please sign in to comment.