我创建了一个 observable,它将在最后一次更改后 3 秒触发,并调用publishChange服务。它可以工作,但我想创建一个doImmediateChange函数,它publishChange立即调用并停止去抖动的 observable。这怎么可能?
我的组件:
class MyComponent {
private updateSubject = new Subject<string>();
ngOnInit() {
this.updateSubject.pipe(
debounceTime(3000),
distinctUntilChanged()
).subscribe(val => {
this.srv.publishChange(val);
});
}
doChange(val: string) {
this.updateSubject.next(val);
}
doImmediateChange(val: string) {
// Stop the current updateSubject if debounce is in progress and call publish immediately
// ??
this.srv.publishChange(val);
}
}
墨色风雨
拉莫斯之舞
茅侃侃
相关分类