Is there a way to execute the second event after the first event is triggered?
In the below example I would like to use scroll event after touchmove event is called.
fromEvent(window, 'touchmove').pipe(
tap(() => this.scroll$.next(false),
debounceTime(100)
).subscribe(() => {
this.scroll$.next(true);
})
If your scroll$ Observable can depend on other observables and don't has to be a Subject you can let it directly depend from the fromEvent Observable.
private sroll$ = fromEvent$(window, 'touchmove').pipe(
switchMapTo(
merge(
of(false),
timer(100).pipe(mapTo(true))
)
)
)
The scroll$ Observable gets triggered by the fromEvent$(window, 'touchmove') Observable. Then we switchMapTo to a combination operator merge:
false value by creating a Observable with only that value (of(false)).timer that fires true 100 ms after.In case you really can't use touchstart and touchend the only way is to use debounceTime pipe
const mousemove$ = fromEvent(document, 'mousemove');
mousemove$
.pipe(
first(),
switchMap(() => mousemove$),
tap(() => this.scroll$.next(false)),
debounceTime(1000)
)
.subscribe(() => {
this.scroll$.next(true);
});