@thi.ng/rstream
Version:
Reactive streams & subscription primitives for constructing dataflow graphs / pipelines
81 lines • 2.86 kB
TypeScript
import type { Predicate } from "@thi.ng/api";
import { type CommonOpts, type ISubscribable, type ISubscription } from "./api.js";
import { ASidechain } from "./asidechain.js";
export interface SidechainPartitionOpts<T> extends CommonOpts {
pred: Predicate<T>;
}
/**
* Returns a subscription which buffers values from `src` until side chain
* delivers its next value, then emits buffer (unless empty) and repeats process
* until either input is done.
*
* @remarks
* By default, the values read from the side chain are ignored (i.e. only their
* timing is used), however the `pred`icate option can be used to only trigger
* for specific values / conditions.
*
* Also see: {@link sidechainToggle}, {@link sidechainTrigger}, {@link syncRAF}.
*
* @example
* ```ts tangle:../export/sidechain-partition.ts
* import { fromEvent, fromRAF, merge, sidechainPartition, trace } from "@thi.ng/rstream";
*
* // merge various event streams
* const events = merge({
* src: [
* fromEvent(document,"mousemove"),
* fromEvent(document,"mousedown"),
* fromEvent(document,"mouseup")
* ]
* });
*
* // queue event processing to only execute during the
* // requestAnimationFrame cycle (RAF)
* sidechainPartition(events, fromRAF()).subscribe(trace())
* ```
*
* @param src -
* @param side -
* @param opts -
*/
export declare const sidechainPartition: <T, S>(src: ISubscribable<T>, side: ISubscribable<S>, opts?: Partial<SidechainPartitionOpts<S>>) => ISubscription<T, T[]>;
/**
* **Deprecated** syntax sugar for one of most common {@link sidechainPartition}
* use cases, to synchronize downstream processing w/ `requestAnimationFrame()`.
* Please use {@link syncRAF} instead.
*
* @remarks
* The returned subscription debounces any high frequency intra-frame input
* values and (if any present), passes only most recent one downstream during
* next RAF event processing.
*
* This example uses thi.ng/atom as state container. Also see {@link fromAtom}
* and {@link syncRAF}.
*
* @example
* ```ts tangle:../export/sidechain-partition-raf.ts
* import { defAtom } from "@thi.ng/atom";
* import { fromAtom, sidechainPartitionRAF } from "@thi.ng/rstream";
*
* const atom = defAtom("alice");
*
* // any change to the atom will only be applied during next RAF update
* sidechainPartitionRAF(fromAtom(atom)).subscribe({
* next(name) { document.body.innerText = name; }
* });
*
* // trigger update
* atom.reset("bob");
* ```
*
* @param src -
*
* @deprecated
*/
export declare const sidechainPartitionRAF: <T>(src: ISubscribable<T>) => ISubscription<T[], T>;
export declare class SidechainPartition<T, S> extends ASidechain<T, S, T[]> {
buf: T[];
constructor(side: ISubscribable<S>, opts?: Partial<SidechainPartitionOpts<S>>);
next(x: T): void;
}
//# sourceMappingURL=sidechain-partition.d.ts.map