仅在退步中如何才能在.next()
上执行Subject
?
let someFlag = true;
if (someFlag) {
someFlag = false;
if (this.resizeDebouncer !== null)) {
this.resizeDebouncer = new Subject<Event>();
this.resizeDebouncer.pipe(
debounceTime(1000)
).subscribe(e => console.log(e.type));
}
}
this.resizeDebouncer.next(event); // should be executed only if resizeDebouncer subject in debouncing progress.
// Don't execute if nothing is running
答案 0 :(得分:0)
我没有发现任何要进行反跳的标记。 .isClosed
和.isStopped
都不适合。但是我已经通过每次订阅内部退订Subject
来解决了我的问题。在这种情况下,订阅仅存在于反跳进度范围内,而其他时间.next()
则不执行任何操作。
let subscription = this.resizeDebouncer
.pipe(debounceTime(300))
.subscribe(e => {
subscription.unsubscribe();
e => console.log(e.type);
});