你需要使用
debounceTime
并增加阈值以跳过不必要的计算,而不是
skip
其省略了初始值。
这样做的优点是,如果字符在阈值内,则只取最后一个值,其余值将被丢弃。
我还为添加了一个代码片段
filter
其中,我们仅在搜索字符串大于3个字符时才运行逻辑。
public ngAfterViewInit(): void {
this.quickFilterValueChange
.pipe(
// filter(() => this.searchStr.length > 3), // you can also use this to limit the initial typing of the search field.
debounceTime(500), // <- threshold is 500ms
distinctUntilChanged(),
tap(() => {
this.store.dispatch(someAction);
}),
takeUntilDestroyed(this.destroyRef),
)
.subscribe();
}