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.
pull/8517/head
gtmnayan 2 years ago committed by GitHub
parent 2cc299185f
commit 6e1674e249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,8 +12,15 @@ export type Updater<T> = (value: T) => T;
/** Cleanup logic callback. */ /** Cleanup logic callback. */
type Invalidator<T> = (value?: T) => void; type Invalidator<T> = (value?: T) => void;
/** Start and stop notification callbacks. */ /**
export type StartStopNotifier<T> = (set: Subscriber<T>) => Unsubscriber | void; * Start and stop notification callbacks.
* This function is called when the first subscriber subscribes.
*
* @param {(value: T) => void} set Function that sets the value of the store.
* @returns {void | (() => void)} Optionally, a cleanup function that is called when the last remaining
* subscriber unsubscribes.
*/
export type StartStopNotifier<T> = (set: (value: T) => void) => void | (() => void);
/** Readable interface for subscribing. */ /** Readable interface for subscribing. */
export interface Readable<T> { export interface Readable<T> {
@ -48,7 +55,7 @@ const subscriber_queue = [];
/** /**
* Creates a `Readable` store that allows reading by subscription. * Creates a `Readable` store that allows reading by subscription.
* @param value initial value * @param value initial value
* @param {StartStopNotifier}start start and stop notifications for subscriptions * @param {StartStopNotifier} [start]
*/ */
export function readable<T>(value?: T, start?: StartStopNotifier<T>): Readable<T> { export function readable<T>(value?: T, start?: StartStopNotifier<T>): Readable<T> {
return { return {
@ -59,7 +66,7 @@ export function readable<T>(value?: T, start?: StartStopNotifier<T>): Readable<T
/** /**
* Create a `Writable` store that allows both updating and reading by subscription. * Create a `Writable` store that allows both updating and reading by subscription.
* @param {*=}value initial value * @param {*=}value initial value
* @param {StartStopNotifier=}start start and stop notifications for subscriptions * @param {StartStopNotifier=} start
*/ */
export function writable<T>(value?: T, start: StartStopNotifier<T> = noop): Writable<T> { export function writable<T>(value?: T, start: StartStopNotifier<T> = noop): Writable<T> {
let stop: Unsubscriber; let stop: Unsubscriber;

Loading…
Cancel
Save