I am trying to make exhaustMap to work, but am not able to. I want to be able to limit the number of api calls. Right now when I search and it's loading, and I type in another value in the input, the code makes a new api call. I want to limit this, so that this does not happen.
loadItems = () => {
const element: any = document.getElementById('type-ahead')
fromEvent(element, 'keyup')
.pipe(
debounceTime(200),
map((e: any) => e.target.value),
distinctUntilChanged(),
exhaustMap(() => interval(1000).pipe(take(10))), // doesnt work, i dont even know why im writing 10 here.
switchMap(this.requestProducts),
tap((data: any) => {
this.page = 1
this.parsedData = data
this.onViewPage()
})
)
.subscribe();
}