【问题标题】:RxJS 6.5.5 startWith deprecated. AlternativeRxJS 6.5.5 startWith 已弃用。选择
【发布时间】:2020-09-04 14:49:07
【问题描述】:

将 Angular 更新到第 9 版并发生在 startWith 函数中,但已弃用。链接到AsyncScheduler 类的文档,但在我的简单情况下如何使用它我不知道:

private subscribeFilters(): void {
  this.filters.valueChanges
    .pipe(
      startWith(this.filters.value),
      pairwise(),
    )
    .subscribe(([prev, next]: [any, any]) => {
      if (JSON.stringify(prev) !== JSON.stringify(next)) {
        this.loadPage();
      }
    });
}

如您所见,我使用startWith 设置过滤器初始状态并在第一次页面加载时排除冗余请求。

如何在没有startWith 的情况下实现相同的逻辑。也许正如文档中所说的 AsyncScheduler 或其他方式?

【问题讨论】:

标签: rxjs rxjs6


【解决方案1】:

我认为this.filtersthis.filters.valueany,这会导致问题,因为any 匹配SchedulerLike

尝试正确键入它们,然后它将不再被检测为SchedulerLike,并且该通知应该消失了。

【讨论】:

  • type them correctly 是什么意思?当我使用startWith<any, any> 时,弃用已消失,但类似于 hack。
  • 我的意思是public filter: {value: string},类似的东西。但是,如果泛型有效并删除了通知 - 它也是可以接受的。主要目标是让 TS 或 Lint 知道它不是 SchedulerLike 签名。
  • 我明白了。谢谢!
猜你喜欢
  • 2019-10-27
  • 2019-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-23
  • 2019-06-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多