Let's dive into the concept of combineLatestAll
after understanding the behavior of combineLatest
.
By referring to the marble diagram linked here, we see that when we have two data streams, combineLatest
combines the latest values from these streams.
Essentially, combineLatest
waits for both subscribed streams to emit data before producing any output.
But what happens if one stream finishes before the other begins?
var stream1 = of(5, 15, 25);
var stream2 = of(6, 16, 26);
var combinedStream = combineLatest([stream1, stream2]);
combinedStream.subscribe(console.log) // Outputs = [25,6] [25,16] and [25, 26]
In such scenarios, combineLatest
takes the latest value from the first source (25 in this case) and then pairs it with incoming values from the second stream once it starts emitting.
Now, let's consider a case with three sources. combineLatest
will only produce an output once all three streams are actively emitting data.
var source1 = of(5, 15, 25);
var source2 = of(6, 16, 26);
var source3 = of(7, 17, 27);
var combinedStreams = combineLatest([source1, source2, source3]);
combinedStreams.subscribe(console.log) // Outputs = [25,26, 7] [25,26, 17] and [25, 26, 27]
In this case, the output reflects the latest values from the first two sources paired with the values from the third source as it emits.
The same concept can be achieved through combineLatestAll
as shown in the example snippet provided.
So, your query demonstrates the typical behavior where the latest values from the first two sources are combined with each value from the last observable.