Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda