peculiar behavior of rxjs SwitchMap while calling an HTTP Service

290 Views Asked by At

I have rxjs SwitchMap which calls an HTTP service that returns an HTTP observable. But the switchmap hits only the first time or until the first result retrieved. after that it does not execute no matter how much I push in behavior or replay subject.

selectedView$ = new ReplaySubject<View>();

ngOnInit(): void {
    combineLatest(([this.selectedView$, this.customer$]))
    .pipe(
      switchMap(([view, customer]) => {
        //this.loading = true;
        return this.cogniteService.getCogniteWellbores(customer.id, view?.cognite?.projectName, View.getPerimeter(view));
      }),
      tap(wb => {
        this.store.dispatch(this.cogniteActions.loadWellbores(wb));
        this.loading = false;
      }),
      catchError( err => {
        this.loading = false;
        this.cdr.markForCheck();
        this.showError.showError(err);
        return of(0);
      }),
      takeUntil(this.destroy$)
    ).subscribe();
  }

while I do next to the selectedView it does not hit the switchmap part. But if put any other code without this HTTP call. then it hits. such as:

combineLatest(([this.selectedView$, this.customer$]))
    .pipe(
      switchMap(([view, customer]) => {
        //this.loading = true;
        return new Observable<Wellbore[]>();
      }),
      tap(wb => {
        this.store.dispatch(this.cogniteActions.loadWellbores(wb));
        this.loading = false;
      }),
      catchError( err => {
        this.loading = false;
        this.cdr.markForCheck();
        this.showError.showError(err);
        return of(0);
      }),
      takeUntil(this.destroy$)
 ).subscribe();
0

There are 0 best solutions below