import { get_store_value } from 'hamber/internal'; /** Callback to inform of a value updates. */ export type Subscriber = (value: T) => void; /** Unsubscribes from value updates. */ export type Unsubscriber = () => void; /** Callback to update a value. */ export type Updater = (value: T) => T; /** Cleanup logic callback. */ type Invalidator = (value?: T) => 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 = (set: (value: T) => void) => void | (() => void); /** Readable interface for subscribing. */ export interface Readable { /** * Subscribe on value changes. * @param run subscription callback * @param invalidate cleanup callback */ subscribe(this: void, run: Subscriber, invalidate?: Invalidator): Unsubscriber; } /** Writable interface for both updating and subscribing. */ export interface Writable extends Readable { /** * Set value and inform subscribers. * @param value to set */ set(this: void, value: T): void; /** * Update value using callback and inform subscribers. * @param updater callback */ update(this: void, updater: Updater): void; } /** * Creates a `Readable` store that allows reading by subscription. * @param value initial value * @param {StartStopNotifier} [start] */ export declare function readable(value?: T, start?: StartStopNotifier): Readable; /** * Create a `Writable` store that allows both updating and reading by subscription. * @param {*=}value initial value * @param {StartStopNotifier=} start */ export declare function writable(value?: T, start?: StartStopNotifier): Writable; /** One or more `Readable`s. */ type Stores = Readable | [Readable, ...Array>] | Array>; /** One or more values from `Readable` stores. */ type StoresValues = T extends Readable ? U : { [K in keyof T]: T[K] extends Readable ? 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 declare function derived(stores: S, fn: (values: StoresValues, set: (value: T) => void) => Unsubscriber | void, initial_value?: T): Readable; /** * 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 - initial value */ export declare function derived(stores: S, fn: (values: StoresValues) => T, initial_value?: T): Readable; /** * 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 */ export declare function derived(stores: S, fn: (values: StoresValues) => T): Readable; /** * Takes a store and returns a new one derived from the old one that is readable. * * @param store - store to make readonly */ export declare function readonly(store: Readable): Readable; /** * Get the current value from a store by subscribing and immediately unsubscribing. * @param store readable */ export { get_store_value as get };