angular - 如何限制 ngxs @Select observable

标签 angular rxjs ngxs

我正在构建一个 application使用 ngxs 作为我的状态管理器。我的应用程序显示分页的消息源,但所有消息都处于状态,在我的例子中大约有 1000 条消息。我有a selector它对帖子进行分页,但是当应用程序最初加载时,随着帖子的进入,我的性能消耗很大。

我尝试了这样激进的方法:

    this.currentFeedSettings = this
        .store
        .select(CurrentFeedSettingState)
        .pipe(
            throttleTime(10000),
        );

但有些消息几乎立即显示,但 10 秒后才显示。我做错了什么吗?

最佳答案

我会推荐debounce运算符。

debounce delays values emitted by the source Observable, but drops previous pending delayed emissions if a new value arrives on the source Observable. This operator keeps track of the most recent value from the source Observable, and spawns a duration Observable by calling the durationSelector function.

在您的代码中,它看起来像:

this.store
  .select(CurrentFeedSettingState)
  .pipe(debounceTime(100))
  .subscribe((res) => { ... });

关于angular - 如何限制 ngxs @Select observable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50621903/

相关文章:

asp.net - Angular 2 无法使用 asp.net MVC 5 Web Api 调用自定义 Web Api

Angular Material cdk-virtual-scroll-viewport : How to render multiple items per row?

angular - HTTP post 405 方法不允许

javascript - rxjs 在 map Rx.Observable.range(1, 5).map 中使用 async/await

javascript - 401 错误时 Angular 2 刷新访问 token 并重复初始请求

Angular 5 : NGXS & route resolvers

html - Angular 4 在 *ngFor 内调用函数时卡住

angular - 在哪里初始化 Angular 4 组件中的变量 - ExpressionChangedAfterItHasBeenCheckedError

angular - 如何将服务注入(inject)到必须在 Angular 7 的应用程序模块中实例化的类中?

angular - 在 NGXS 中组合多个 @Select