@epikodelabs/streamix / src/public-api / withLatestFrom
Function: withLatestFrom()
Call Signature
withLatestFrom<
T,R>(...args):Operator<T, [T,...R[]]>
Defined in: projects/libraries/streamix/src/lib/operators/withLatestFrom.ts:49
Combines the source stream with the latest values from one or more auxiliary streams or promises.
When the source stream emits a value, this operator emits a tuple containing that source value along with the most recent values from each auxiliary input.
Type Parameters
T
T = any
The type of values emitted by the source stream.
R
R extends readonly unknown[] = readonly unknown[]
A readonly array/tuple representing the types emitted by the auxiliary streams.
Parameters
args
...{ [K in string | number | symbol]: WithLatestInput<R[K<K>]> }
One or more streams, promises, or an array of streams/promises whose latest values will be combined with the source value.
Returns
Operator<T, [T, ...R[]]>
A push operator function that transforms the source stream into a stream of combined tuples.
Example
const clicks = listen(document, 'click');
const mouseMoves = listen(document, 'mousemove');
pipe(clicks, withLatestFrom(mouseMoves)).subscribe({
next: ([clickEvent, lastMouseMove]) => {
console.log('Clicked at:', lastMouseMove.clientX, lastMouseMove.clientY);
}
});Call Signature
withLatestFrom<
T,R>(args):Operator<T, [T,...R[]]>
Defined in: projects/libraries/streamix/src/lib/operators/withLatestFrom.ts:52
Combines the source stream with the latest values from one or more auxiliary streams or promises.
When the source stream emits a value, this operator emits a tuple containing that source value along with the most recent values from each auxiliary input.
Type Parameters
T
T = any
The type of values emitted by the source stream.
R
R extends readonly unknown[] = readonly unknown[]
A readonly array/tuple representing the types emitted by the auxiliary streams.
Parameters
args
{ [K in string | number | symbol]: WithLatestInput<R[K<K>]> }
One or more streams, promises, or an array of streams/promises whose latest values will be combined with the source value.
Returns
Operator<T, [T, ...R[]]>
A push operator function that transforms the source stream into a stream of combined tuples.
Example
const clicks = listen(document, 'click');
const mouseMoves = listen(document, 'mousemove');
pipe(clicks, withLatestFrom(mouseMoves)).subscribe({
next: ([clickEvent, lastMouseMove]) => {
console.log('Clicked at:', lastMouseMove.clientX, lastMouseMove.clientY);
}
});