@thi.ng/rstream
Version:
Reactive streams & subscription primitives for constructing dataflow graphs / pipelines
47 lines • 1.62 kB
TypeScript
import { type CommonOpts, type ISubscribable } from "./api.js";
import { Subscription } from "./subscription.js";
/**
* Similar to (in in effect the same as the **now deprecated**)
* {@link sidechainPartitionRAF}, however more performant & lightweight.
* Synchronizes downstream processing w/ `requestAnimationFrame()`. The returned
* subscription delays & debounces any high frequency intra-frame input values
* and passes only most recent one downstream during next RAF event processing.
*
* This example uses thi.ng/atom as state container. Also see {@link fromAtom}.
*
* See {@link sidechainTrigger} from a similar & more general construct.
*
* @example
* ```ts tangle:../export/sync-raf.ts
* import { defAtom } from "@thi.ng/atom";
* import { fromAtom, syncRAF } from "@thi.ng/rstream";
*
* const atom = defAtom("alice");
*
* // any changes to the atom will only be received by this subscription
* // during next RAF update cycle
* syncRAF(fromAtom(atom)).subscribe({
* next({ name }) { document.body.innerText = name; }
* });
*
* // trigger update
* atom.reset("bob");
* ```
*
* @param src -
* @param opts -
*/
export declare const syncRAF: <T>(src: ISubscribable<T>, opts?: Partial<CommonOpts>) => import("./api.js").ISubscription<T, T>;
/**
* See {@link syncRAF} for details.
*/
export declare class SyncRAF<T> extends Subscription<T, T> {
queued?: T;
raf?: number | NodeJS.Timeout;
constructor(opts?: Partial<CommonOpts>);
next(x: T): void;
done(): void;
error(e: any): boolean;
protected _clean(): void;
}
//# sourceMappingURL=sync-raf.d.ts.map