微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决调用 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 举报,一经查实,本站将立刻删除。