Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why `combineLatest` returns OperatorFunction<{}, number>

Tags:

angular

rxjs

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

like image 778
Abrkad Avatar asked May 15 '18 07:05

Abrkad


People also ask

Does combineLatest complete?

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.

Does combineLatest wait?

I call combineLatest operator the independent operator. They are independent and don't wait for each other.

What is combineLatest in Rxjava?

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.


2 Answers

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';
like image 53
martin Avatar answered Nov 08 '22 00:11

martin


I am guessing I just need this

import { combineLatest } from 'rxjs';
like image 28
Abrkad Avatar answered Nov 07 '22 22:11

Abrkad