Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to bypass debounceTime in angular

I have this text input with a debounceTime pipe, so that we don’t hit the server too often while the user is typing the word:

this.keyUp$
  .pipe(debounceTime(500))
  .subscribe(data => this.onInputChanged.emit(data));

However, if the user hits Enter after entering the data, I would like to call onInputChanged immediately.

How can I bypass the debounceTime pipe depending on the key?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can merge your streams after debounceTime

this.keyUp$.pipe(
        debounceTime(500),
        mergeWith(this.keyEnter$))
       .subscribe(data => this.onInputChanged.emit(data));

just keep in mind that after debounce time it will still emmit, so you have to add additiona filtering to ignore this pipeline if request is already in progress

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading