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

204
Vistas
How to replace debounceTime(0) to emit when needed?

I have a similar use case to this

import { BehaviorSubject, combineLatest } from 'rxjs'
import { map, debounceTime } from 'rxjs/operators'

const items$ = new BehaviorSubject([]);
const size$ = new BehaviorSubject(10);

const visibleItems$ = combineLatest([items$, size$])
  .pipe(
    debounceTime(0),
    map(([items, size]) => items.slice(0, size))
  );

And some times I have this scenario

const onData = bigArr => {
  items$.next(bigArr);
}

Sometimes this

const changeSize = () => {
  size$.next(20);
}

And sometimes this

const onData2 = bigArr => {
  items$.next(bigArr);
  size$.next(10);
}

I don't want to trigger the visibleItems$ observable flow multiple times, so a solution that I've found is use the debounceTime operator with 0 ms to perform the onData2 method without running the pipe operators twice, but it is a bit hard to reason this operator (at least from the first glance). How can I replace it, so my code is easier to understand?

about 4 years ago · Juan Pablo Isaza
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