Javascript 检查debounceTime()进程中是否可观察到
仅当Javascript 检查debounceTime()进程中是否可观察到,javascript,typescript,rxjs,observable,subject,Javascript,Typescript,Rxjs,Observable,Subject,仅当主题处于去抖动过程中时,如何才能对其执行.next() let someFlag = true; if (someFlag) { someFlag = false; if (this.resizeDebouncer !== null)) { this.resizeDebouncer = new Subject<Event>(); this.resizeDebouncer.pipe(
主题
处于去抖动过程中时,如何才能对其执行.next()
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
让someFlag=true;
if(someFlag){
someFlag=false;
如果(this.resizeDebouncer!==null)){
this.resizeDebouncer=新主题();
这是一个大口径的烟斗(
去BounceTime(1000)
).subscribe(e=>console.log(e.type));
}
}
this.resizeDebouncer.next(event);//只有在取消公告过程中重新调整公告者主题时才应执行。
//如果没有任何运行,则不执行
我没有找到任何正在进行的去抖动标记。.isClosed
和.isStopped
都不适合。但我已经解决了我的问题,每次在订阅中取消订阅Subject
。在这种情况下,订阅仅存在于取消绑定进度范围内,而在其他时间。next()
不起任何作用
let subscription = this.resizeDebouncer
.pipe(debounceTime(300))
.subscribe(e => {
subscription.unsubscribe();
e => console.log(e.type);
});