Here is my code:
app.component.ts
notifier$ = new BehaviorSubject<any>({});
notify() {
this.notifier$.next({});
}
app.component.html
<div (scroll)="notify()"></div>
<child-component [inp]="notifier$ | async" />
The problem is that when a user is scrolling, the notify()
function is called repeatedly and I only want to call notify()
once each time the user starts to scroll.
I can accomplish what I want this way:
scrolling = false;
scrollingTimer: NodeJS.Timer;
notify() {
clearTimeout(this.scrollingTimer);
if (!this.scrolling) {
this.notifier$.next({});
}
this.scrolling = true;
this.scrollingTimer = setTimeout(() => (this.scrolling = false), 1000);
}
but I would like to do this with rxjs
. However debounceTime
is the opposite of what I want, and neither throttleTime
nor auditTime
are what I want either. Is there a way to do this?