So, currently I am working with 2 observables.
The
obseravableClickBtn
observable will send a request immediately upon click.The
observableInputText
observable will debounce the requests by 3 seconds.
Here is the code snippet:
obseravableClickBtn = Observable.fromEvent(document.getElementsById('btnSearch'), 'click')
observableInputText = Observable.fromEvent(this.textBoxInput1.nativeElement, 'keyup')
.merge(Observable.fromEvent(this.textBoxInput2.nativeElement, 'keyup')).debounceTime(3000)
My challenge is that during the 3-second debounce period of the observableInputText
, if the btnSearch
is clicked, I want to cancel the observableInputText
observable and immediately send a request instead.
I attempted to solve this using:
const mergeObservable=obseravableClickBtn.merge(observableInputText).switchMap(
()=>sendRequest());
However, I am facing an issue where two requests are being made if I click btnSearch
during the 3-second debounce after inputting. I require only one observable to run at a time. Is there any other operator function available for achieving this?