Agash Thamo.
Agash Thamo.

Reputation: 748

Debounce on one Observable in merge

I have the following merge(), where I merge the events to send a single request to my API:

merge(
  this.sort.sortChange,
  this.paginator.page,
  this.statusSelect.selectionChange,
  this.searchFilterEvent$
)

Now, the first three arguments are the events emitted by Angular Material Directives, the last this.searchFilterEvent$ is an Observable created from fromEvent which is the keyup event on an input. I want that on each event (except the searchFilterEvent) the code below is executed, but have a debounceTime only on the searchEventFilter, so that I don't send a request on every keyup event. Is that possible or do I have to separate them and write the code that's executed on the events twice (or in a function and call the function of course)?

Upvotes: 1

Views: 1518

Answers (1)

martin
martin

Reputation: 96889

You can just chain the one Observable with debounceTime and leave the rest as is:

merge(
  this.sort.sortChange,
  this.paginator.page,
  this.statusSelect.selectionChange,
  this.searchFilterEvent$.pipe(debounceTime(...)),
)

Upvotes: 3

Related Questions