Rxjs: forkJoin doesn't work with observables from ngStore

Created on 7 Nov 2017  路  5Comments  路  Source: ReactiveX/rxjs

Hello. Please, help me with problem.

I use ngStore in my project.
Part code of my project.
user$: Observable = store.select('customer');
customerCarList$: Observable> = store.select(s => s.customerCar.cars);

But, when I try use forkJoin, subsctibe haven't reaction on emit each Observable and both too.

Rx.Observable.forkJoin(
user$,
customerCarList$
).subscribe(val => {
console.log(val);
});

needs info

Most helpful comment

forkJoin requires that the observable that is being forked also completes. In the case of @ngrx, all of their observables are usually based on a BehaviorSubject, and will never complete (under normal circumstances anyway).

In your case you either want to forkJoin(user$.take(1), customCarList$.take(1) or use a different operator that will react to changes such as combineLatest which will emit a value everytime one of the root observables emits.

All 5 comments

Please provide reproducible code to check in behavior. Also worth double check user$ and customerCarList$ both emits and completes.

Hey @pers1307! I recommend creating a reproducible example on stackblitz.com. Super easy to set up and super easy for other to debug.

forkJoin requires that the observable that is being forked also completes. In the case of @ngrx, all of their observables are usually based on a BehaviorSubject, and will never complete (under normal circumstances anyway).

In your case you either want to forkJoin(user$.take(1), customCarList$.take(1) or use a different operator that will react to changes such as combineLatest which will emit a value everytime one of the root observables emits.

Thank you so much @david-driscoll! Your approach is work. I understand it. Close issue please, @kwonoj.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

giovannicandido picture giovannicandido  路  4Comments

unao picture unao  路  4Comments

jakovljevic-mladen picture jakovljevic-mladen  路  3Comments

shenlin192 picture shenlin192  路  3Comments

benlesh picture benlesh  路  3Comments