Skip to content

Commit 8334e32

Browse files
committed
Fixed docs for svelte/store not being rendered
1 parent 999b92d commit 8334e32

File tree

3 files changed

+76
-44
lines changed

3 files changed

+76
-44
lines changed

packages/svelte/src/store/index-client.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import { createSubscriber } from '../reactivity/create-subscriber.js';
1010
export { derived, get, readable, readonly, writable } from './shared/index.js';
1111

1212
/**
13+
* Create a store from a function that returns state, and (to make a writable store), an
14+
* optional second function that sets state.
15+
*
16+
* ```ts
17+
* import { toStore } from 'svelte/store';
18+
*
19+
* let count = $state(0);
20+
*
21+
* const store = toStore(() => count, (v) => (count = v));
22+
* ```
1323
* @template V
1424
* @overload
1525
* @param {() => V} get
@@ -23,16 +33,6 @@ export { derived, get, readable, readonly, writable } from './shared/index.js';
2333
* @returns {Readable<V>}
2434
*/
2535
/**
26-
* Create a store from a function that returns state, and (to make a writable store), an
27-
* optional second function that sets state.
28-
*
29-
* ```ts
30-
* import { toStore } from 'svelte/store';
31-
*
32-
* let count = $state(0);
33-
*
34-
* const store = toStore(() => count, (v) => (count = v));
35-
* ```
3636
* @template V
3737
* @param {() => V} get
3838
* @param {(v: V) => void} [set]
@@ -71,18 +71,6 @@ export function toStore(get, set) {
7171
};
7272
}
7373

74-
/**
75-
* @template V
76-
* @overload
77-
* @param {Writable<V>} store
78-
* @returns {{ current: V }}
79-
*/
80-
/**
81-
* @template V
82-
* @overload
83-
* @param {Readable<V>} store
84-
* @returns {{ readonly current: V }}
85-
*/
8674
/**
8775
* Convert a store to an object with a reactive `current` property. If `store`
8876
* is a readable store, `current` will be a readonly property.
@@ -101,6 +89,18 @@ export function toStore(get, set) {
10189
* count.current += 1;
10290
* get(store); // 2
10391
* ```
92+
* @template V
93+
* @overload
94+
* @param {Writable<V>} store
95+
* @returns {{ current: V }}
96+
*/
97+
/**
98+
* @template V
99+
* @overload
100+
* @param {Readable<V>} store
101+
* @returns {{ readonly current: V }}
102+
*/
103+
/**
104104
* @template V
105105
* @param {Writable<V> | Readable<V>} store
106106
*/

packages/svelte/src/store/index-server.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import { get, writable } from './shared/index.js';
44
export { derived, get, readable, readonly, writable } from './shared/index.js';
55

66
/**
7+
* Create a store from a function that returns state, and (to make a writable store), an
8+
* optional second function that sets state.
9+
*
10+
* ```ts
11+
* import { toStore } from 'svelte/store';
12+
*
13+
* let count = $state(0);
14+
*
15+
* const store = toStore(() => count, (v) => (count = v));
16+
* ```
717
* @template V
818
* @overload
919
* @param {() => V} get
@@ -17,16 +27,6 @@ export { derived, get, readable, readonly, writable } from './shared/index.js';
1727
* @returns {Readable<V>}
1828
*/
1929
/**
20-
* Create a store from a function that returns state, and (to make a writable store), an
21-
* optional second function that sets state.
22-
*
23-
* ```ts
24-
* import { toStore } from 'svelte/store';
25-
*
26-
* let count = $state(0);
27-
*
28-
* const store = toStore(() => count, (v) => (count = v));
29-
* ```
3030
* @template V
3131
* @param {() => V} get
3232
* @param {(v: V) => void} [set]
@@ -48,18 +48,6 @@ export function toStore(get, set) {
4848
};
4949
}
5050

51-
/**
52-
* @template V
53-
* @overload
54-
* @param {Writable<V>} store
55-
* @returns {{ current: V }}
56-
*/
57-
/**
58-
* @template V
59-
* @overload
60-
* @param {Readable<V>} store
61-
* @returns {{ readonly current: V }}
62-
*/
6351
/**
6452
* Convert a store to an object with a reactive `current` property. If `store`
6553
* is a readable store, `current` will be a readonly property.
@@ -78,6 +66,18 @@ export function toStore(get, set) {
7866
* count.current += 1;
7967
* get(store); // 2
8068
* ```
69+
* @template V
70+
* @overload
71+
* @param {Writable<V>} store
72+
* @returns {{ current: V }}
73+
*/
74+
/**
75+
* @template V
76+
* @overload
77+
* @param {Readable<V>} store
78+
* @returns {{ readonly current: V }}
79+
*/
80+
/**
8181
* @template V
8282
* @param {Writable<V> | Readable<V>} store
8383
*/

packages/svelte/types/index.d.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,10 +2148,42 @@ declare module 'svelte/store' {
21482148
*/
21492149
update(this: void, updater: Updater<T>): void;
21502150
}
2151+
2152+
/**
2153+
* Create a store from a function that returns state, and (to make a writable store), an
2154+
* optional second function that sets state.
2155+
*
2156+
* ```ts
2157+
* import { toStore } from 'svelte/store';
2158+
*
2159+
* let count = $state(0);
2160+
*
2161+
* const store = toStore(() => count, (v) => (count = v));
2162+
* ```
2163+
*/
21512164
export function toStore<V>(get: () => V, set: (v: V) => void): Writable<V>;
21522165

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

2168+
/**
2169+
* Convert a store to an object with a reactive `current` property. If `store`
2170+
* is a readable store, `current` will be a readonly property.
2171+
*
2172+
* ```ts
2173+
* import { fromStore, get, writable } from 'svelte/store';
2174+
*
2175+
* const store = writable(0);
2176+
*
2177+
* const count = fromStore(store);
2178+
*
2179+
* count.current; // 0;
2180+
* store.set(1);
2181+
* count.current; // 1
2182+
*
2183+
* count.current += 1;
2184+
* get(store); // 2
2185+
* ```
2186+
*/
21552187
export function fromStore<V>(store: Writable<V>): {
21562188
current: V;
21572189
};

0 commit comments

Comments
 (0)