UNPKG

@2toad/reflex

Version:

A simple approach to state management

64 lines 3.34 kB
import type { Reflex, ReflexWithError, ProjectFunction } from "./types"; /** * Maps values from a source reflex using a transform function * @param source The source reflex to map from * @param fn The transform function to apply to each value */ export declare function map<T, R>(source: Reflex<T>, fn: (value: T) => R): ReflexWithError<R>; /** * Filters values from a source reflex using a predicate function * @param source The source reflex to filter * @param predicate The function to test each value */ export declare function filter<T>(source: Reflex<T>, predicate: (value: T) => boolean): Reflex<T>; /** * Merges multiple reflex sources into a single reflex that emits whenever any source emits * @param sources Array of reflex sources to merge */ export declare function merge<T>(sources: ReadonlyArray<Reflex<T>>): Reflex<T>; /** * Combines multiple reflex sources into a single reflex that emits arrays of their latest values * @param sources Array of reflex sources to combine */ export declare function combine<T extends unknown[]>(sources: ReadonlyArray<Reflex<T[number]>>): Reflex<T>; /** * Creates a reflex that accumulates values over time using a reducer function * @param source The source reflex * @param reducer The reducer function to accumulate values * @param seed The initial accumulator value */ export declare function scan<T, R>(source: Reflex<T>, reducer: (acc: R, value: T) => R, seed: R): Reflex<R>; /** * Debounces a reflex source, only emitting after a specified delay has passed without any new emissions * @param source The source reflex to debounce * @param delayMs The delay in milliseconds */ export declare function debounce<T>(source: Reflex<T>, delayMs: number): Reflex<T>; /** * Projects each value from the source to an inner reflex, cancelling previous projections * when a new value arrives. Like map, but for async/reflex operations where only the latest matters. * @param source The source reflex * @param project Function that returns a reflex or promise for each source value */ export declare function switchMap<T, R>(source: Reflex<T>, project: ProjectFunction<T, R>): Reflex<R>; /** * Projects each value from the source to an inner reflex, maintaining all active projections * concurrently. Like map, but for async/reflex operations that should run in parallel. * @param source The source reflex * @param project Function that returns a reflex or promise for each source value */ export declare function mergeMap<T, R>(source: Reflex<T>, project: ProjectFunction<T, R>): Reflex<R>; /** * Projects each value from the source to an inner reflex, processing projections in sequence. * Like map, but for async/reflex operations that must complete in order. * @param source The source reflex * @param project Function that returns a reflex or promise for each source value */ export declare function concatMap<T, R>(source: Reflex<T>, project: ProjectFunction<T, R>): Reflex<R>; /** * Catches errors in a reflex stream and allows for recovery or fallback values * @param source The source reflex * @param errorHandler Function that returns a reflex or value to recover from the error */ export declare function catchError<T, R>(source: Reflex<T>, errorHandler: (error: Error) => Reflex<R> | R): Reflex<T | R>; //# sourceMappingURL=operators.d.ts.map