|
|
|
@ -13,7 +13,7 @@ export type Updater<T> = (value: T) => T;
|
|
|
|
type Invalidator<T> = (value?: T) => void;
|
|
|
|
type Invalidator<T> = (value?: T) => void;
|
|
|
|
|
|
|
|
|
|
|
|
/** Start and stop notification callbacks. */
|
|
|
|
/** 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. */
|
|
|
|
/** Readable interface for subscribing. */
|
|
|
|
export interface Readable<T> {
|
|
|
|
export interface Readable<T> {
|
|
|
|
@ -125,7 +125,21 @@ type StoresValues<T> = T extends Readable<infer U> ? U :
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function derived<S extends Stores, T>(
|
|
|
|
export function derived<S extends Stores, T>(
|
|
|
|
stores: S,
|
|
|
|
stores: S,
|
|
|
|
fn: (values: StoresValues<S>, set: Subscriber<T>, update?: (fn: Updater<T>) => void) => Unsubscriber | void,
|
|
|
|
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.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @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>) => Unsubscriber | void,
|
|
|
|
initial_value?: T
|
|
|
|
initial_value?: T
|
|
|
|
): Readable<T>;
|
|
|
|
): Readable<T>;
|
|
|
|
|
|
|
|
|
|
|
|
|