import { EqualityComparator, ReadonlyStore } from './store.js'; /** * Configurations for derived stores. */ export type DerivedStoreConfig = { /** * (optional, defaults to `(a, b) => a === b`) a function that's used to determine if the current value of the store value is different from * the one being set and thus if the store needs to be updated and the subscribers notified. */ comparator?: EqualityComparator; }; /** * Create a derived store. * * Example usage: * ```ts * const source$ = makeStore(10); * const derived$ = makeDerivedStore(source$, (v) => v * 2); * source$.subscribe((v) => console.log(v)); // prints 10 * derived$.subscribe((v) => console.log(v)); // prints 20 * source$.set(16); // triggers both console.logs, printing 16 and 32 * ``` * @param readonlyStore a store or readonly store. * @param map a function that takes the current value of the source store and maps it to another value. * @param config a {@link DerivedStoreConfig} which contains configuration information such as a value comparator to avoid needless notifications to subscribers. */ export declare function makeDerivedStore(readonlyStore: ReadonlyStore, map: (value: TIn) => TOut, config?: DerivedStoreConfig): ReadonlyStore; /** * Create a derived store from multiple sources. * * Example usage: * ```ts * const source1$ = makeStore(10); * const source2$ = makeStore(-10); * const derived$ = makeDerivedStore([source1$, source2$], ([v1, v2]) => v1 + v2); * source1$.subscribe((v) => console.log(v)); // prints 10 * source2$.subscribe((v) => console.log(v)); // prints -10 * derived$.subscribe((v) => console.log(v)); // prints 0 * source1$.set(11); // prints 11 (first console.log) and 1 (third console.log) * source2$.set(9); // prints 9 (second console.log) and 20 (third console.log) * ``` * @param readonlyStores an array of stores or readonly stores. * @param map a function that takes the current value of all the source stores and maps it to another value. * @param config a {@link DerivedStoreConfig} which contains configuration information such as a value comparator to avoid needless notifications to subscribers. */ export declare function makeDerivedStore(readonlyStores: { [K in keyof TIn]: ReadonlyStore; }, map: (value: { [K in keyof TIn]: TIn[K]; }) => TOut, config?: DerivedStoreConfig): ReadonlyStore; /** * Create a derived store from multiple sources. * * Example usage: * ```ts * const source1$ = makeStore(10); * const source2$ = makeStore(-10); * const derived$ = makeDerivedStore({v1: source1$, v2: source2$}, ({v1, v2}) => v1 + v2); * source1$.subscribe((v) => console.log(v)); // prints 10 * source2$.subscribe((v) => console.log(v)); // prints -10 * derived$.subscribe((v) => console.log(v)); // prints 0 * source1$.set(11); // prints 11 (first console.log) and 1 (third console.log) * source2$.set(9); // prints 9 (second console.log) and 20 (third console.log) * ``` * @param readonlyStores an array of stores or readonly stores. * @param map a function that takes the current value of all the source stores and maps it to another value. * @param config a {@link DerivedStoreConfig} which contains configuration information such as a value comparator to avoid needless notifications to subscribers. */ export declare function makeDerivedStore(readonlyStores: { [K in keyof TIn]: ReadonlyStore; }, map: (value: { [K in keyof TIn]: TIn[K]; }) => TOut, config?: DerivedStoreConfig): ReadonlyStore;