Skip to content

Commit

Permalink
StartStopNotifier type now requires update param
Browse files Browse the repository at this point in the history
This will be a breaking change for anyone who uses the StartStopNotifier
type in their custom stores.
  • Loading branch information
rmunn committed Sep 27, 2021
1 parent b2b7bd1 commit a7e2a61
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/runtime/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type Updater<T> = (value: T) => T;
type Invalidator<T> = (value?: T) => void;

/** Start and stop notification callbacks. */
export type StartStopNotifier<T> = (set: Subscriber<T>, update?: (fn: Updater<T>) => void) => Unsubscriber | void;
export type StartStopNotifier<T> = (set: Subscriber<T>, update: (fn: Updater<T>) => void) => Unsubscriber | void;

/** Readable interface for subscribing. */
export interface Readable<T> {
Expand Down Expand Up @@ -115,6 +115,20 @@ type Stores = Readable<any> | [Readable<any>, ...Array<Readable<any>>] | Array<R
type StoresValues<T> = T extends Readable<infer U> ? U :
{ [K in keyof T]: T[K] extends Readable<infer U> ? U : never };

/**
* Derived value store by synchronizing one or more readable stores and
* applying an aggregation function over its input values.
*
* @param stores - input stores
* @param fn - function callback that aggregates the values
* @param initial_value - when used asynchronously
*/
export function derived<S extends Stores, T>(
stores: S,
fn: (values: StoresValues<S>, set: Subscriber<T>, update: (fn: Updater<T>) => void) => Unsubscriber | void,
initial_value?: T
): Readable<T>;

/**
* Derived value store by synchronizing one or more readable stores and
* applying an aggregation function over its input values.
Expand All @@ -125,7 +139,7 @@ type StoresValues<T> = T extends Readable<infer U> ? U :
*/
export function derived<S extends Stores, T>(
stores: S,
fn: (values: StoresValues<S>, set: Subscriber<T>, update?: (fn: Updater<T>) => void) => Unsubscriber | void,
fn: (values: StoresValues<S>, set: Subscriber<T>) => Unsubscriber | void,
initial_value?: T
): Readable<T>;

Expand Down

0 comments on commit a7e2a61

Please sign in to comment.