调用 HTTP 服务时 rxjs SwitchMap 的特殊行为

问题描述

我有 rxjs SwitchMap,它调用返回 HTTP 可观察的 HTTP 服务。但是 switchmap 只在第一次命中或直到检索到第一个结果。之后,无论我如何推动行为或重播主题,它都不会执行。

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();
  }

当我在 selectedView 旁边做时,它没有碰到 switchmap 部分。但是如果在没有这个 HTTP 调用的情况下放置任何其他代码。然后它击中。例如:

combineLatest(([this.selectedView$,customer]) => {
        //this.loading = true;
        return new Observable<Wellbore[]>();
      }),takeuntil(this.destroy$)
 ).subscribe();

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)