Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
How to execute the second event after the first event is triggered

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);
})

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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:

  • This way we can instantly return a false value by creating a Observable with only that value (of(false)).
  • Furthermore we can start a timer that fires true 100 ms after.
over 4 years ago · Santiago Trujillo Report

0

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);
      });

Stackblitz demo

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!