I am using RxJS 6
I have two observables in my code
import { combineLatest } from 'rxjs/operators';
loading$: Observable<boolean>;
loaded$: Observable<boolean>;
The observables are not coming from http
request but from the store
I need to combine/convert the sequences into one single observable value based on this logic:
If the sequence true
, true
or false
, false
- need to return new observable true
otherwise need to return false
I tried to use combineLatest
to achieve that:
combineLatest(
this.loaded$, this.loading$,
(val1, val2) => Number(val1) + Number(val2) === 1
)
But the problem is that my combineLatest
returns 'OperatorFunction<>
and not Observable<>
so I cannot subscribe.
Do you have any ideas on how to fix that? Or if there is another approach that can be taken?
UPDATE:
Seems like that is the answer to my question import { combineLatest } from 'RxJS';
currently testing
It will never complete if any of the inner streams doesn't complete. On the other hand, if any stream does not emit value but completes, resulting stream will complete at the same moment without emitting anything, since it will be now impossible to include value from completed input stream in resulting sequence.
I call combineLatest operator the independent operator. They are independent and don't wait for each other.
combineLatest() factory is somewhat similar to zip() , but for every emission that fires from one of the sources, it will immediately couple up with the latest emission from every other source. It will not queue up unpaired emissions for each source, but rather cache and pair the latest one.
With RxJS 5.5 it's most likely because you're using combineLatest
from rxjs/operators
while you want to use it as an Observable "creation method" which means you need to use rxjs/observable/combineLatest
.
I mean you need to use this:
import { combineLatest } from 'rxjs/observable/combineLatest';
... instead of this:
import { combineLatest } from 'rxjs/operators';
Edit: Since you mentioned you're using RxJS 6 you can import the static variant from rxjs
.
import { combineLatest } from 'rxjs';
If you're looking for combineLatest
operator you have to import it like this:
import { combineLatest } from 'rxjs/operators';
I am guessing I just need this
import { combineLatest } from 'rxjs';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With