skip to content

withLatestFrom

 

Creates a combined stream from source and other provided streams.
When source emits a value — resulting Observable will emit a combined value of source emission and all latest values on provided streams.

Also take a look at rxjs/autorun package that let's you easily combine multiple streams emissions in any form

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const { rxObserver } = require('api/v0.3');
const { timer } = require('rxjs');
const { withLatestFrom, take } = require('rxjs/operators');


const a$ = timer(0, 10).pipe(
    take(5)
  );

const b$ = timer(0, 4).pipe(
    take(7)
  );

const result$ = a$.pipe(
  withLatestFrom(b$)
);

a$.subscribe(rxObserver('a$'));
b$.subscribe(rxObserver('b$'));
result$.subscribe(rxObserver('a$ :: withLatestFrom(b$)'));

0msa$startcomplete00 11 22 33 44 b$startcomplete00 11 22 33 44 55 66 a$ :: withLatestFrom(b$)startcomplete[0,0][0,0] [1,2][1,2] [2,4][2,4] [3,6][3,6] [4,6][4,6]