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

481
Views
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?

over 4 years ago · Santiago Trujillo
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!