Option forkJoin for incomplete observables?

constructor(
    private route: ActivatedRoute,
    private http: Http
){
    // Observe parameter changes
    let paramObs = route.paramMap;

    // Fetch data once
    let dataObs = http.get('...');

    // Subscribe to both observables,
    // use both resolved values at the same level
}

Is there something similar to forkJointhat that works every time a parameter is changed? forkJoinonly works when all observables are complete.

I just need to avoid the callback hell, any alternative that matches is appreciated.

+6
source share
2 answers

There are several options:

  1. Use take(1)c forkJoin()to complete each Observable source:

    forkJoin(o1$.take(1), o2$.take(1))
    
  2. Use and to radiate only when all of the original Observed objects have released the same number of elements: zip()take(1)

    zip(o1$, o2$).take(1)
    
  3. combineLatest() combineLatest() Observables :

    combineLatest(o1$, o2$)
    

2019: RxJS 6

+10

Observable.concat() . :

const getPostOne$ = Rx.Observable.timer(3000).mapTo({id: 1});
const getPostTwo$ = Rx.Observable.timer(1000).mapTo({id: 2});

Rx.Observable.concat(getPostOne$, getPostTwo$).subscribe(res => console.log(res));

6 , .

+1

Source: https://habr.com/ru/post/1681723/


All Articles