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?
CodePudding user response:
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