Skip to content

Commit 6e1674e

Browse files
authored
docs: fix type signature for StartStopNotifier (#8509)
It used the Subscriber type to represent the set callback and the Unsubscriber to represent the cleanup callback. But the names made it confusing what it was for.
1 parent 2cc2991 commit 6e1674e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/runtime/store/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ export type Updater<T> = (value: T) => T;
1212
/** Cleanup logic callback. */
1313
type Invalidator<T> = (value?: T) => void;
1414

15-
/** Start and stop notification callbacks. */
16-
export type StartStopNotifier<T> = (set: Subscriber<T>) => Unsubscriber | void;
15+
/**
16+
* Start and stop notification callbacks.
17+
* This function is called when the first subscriber subscribes.
18+
*
19+
* @param {(value: T) => void} set Function that sets the value of the store.
20+
* @returns {void | (() => void)} Optionally, a cleanup function that is called when the last remaining
21+
* subscriber unsubscribes.
22+
*/
23+
export type StartStopNotifier<T> = (set: (value: T) => void) => void | (() => void);
1724

1825
/** Readable interface for subscribing. */
1926
export interface Readable<T> {
@@ -48,7 +55,7 @@ const subscriber_queue = [];
4855
/**
4956
* Creates a `Readable` store that allows reading by subscription.
5057
* @param value initial value
51-
* @param {StartStopNotifier}start start and stop notifications for subscriptions
58+
* @param {StartStopNotifier} [start]
5259
*/
5360
export function readable<T>(value?: T, start?: StartStopNotifier<T>): Readable<T> {
5461
return {
@@ -59,7 +66,7 @@ export function readable<T>(value?: T, start?: StartStopNotifier<T>): Readable<T
5966
/**
6067
* Create a `Writable` store that allows both updating and reading by subscription.
6168
* @param {*=}value initial value
62-
* @param {StartStopNotifier=}start start and stop notifications for subscriptions
69+
* @param {StartStopNotifier=} start
6370
*/
6471
export function writable<T>(value?: T, start: StartStopNotifier<T> = noop): Writable<T> {
6572
let stop: Unsubscriber;

0 commit comments

Comments
 (0)