Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda