...
/Adding Debounce to the Typeahead
Adding Debounce to the Typeahead
Let's see how Rx makes our life peaceful and how easy it is to add a debounced function using Rx compared to the vanilla JavaScript code.
We'll cover the following...
Debouncing time using vanilla code
Let’s see how the vanilla snippet fares when adding debouncing:
Press + to interact
let latestQuery;searchBar.addEventListener('keyup', debounce(event => {let searchVal = latestQuery = event.target.value;fetch(endpoint + searchVal).then(results => {if (searchVal === latestQuery) {updatePage(results);}});}));
event
function is debounced, which