我正在构建一个 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/