This is the marble diagram for a RxJs
swithmap
function.
Reference: https://rxjs.dev/api/operators/switchMap
My questions are:
- What is the large space between 1 & 3 and small space between 3 & 5 mean? Is it duration in seconds between those numbers when they are emitted?
- In this diagram, what are inner observable and outer observable?
- The last line shows 30 and 50 together. Why the third 30 disappeared?
- More confusing to me is the following code. The output is consistent and print all 9 values. The result is not 8 values like shown in the marble diagram where some values like 30 is ignored.
const switched = of(1, 2, 3).pipe(switchMap(x => of(x, x ** 2, x ** 3)));
switched.subscribe(x => console.log(x));
// outputs
// 1
// 1
// 1
// 2
// 4
// 8
// 3
// 9
// 27