What Is Debouncing ?
“debouncing is any kind of hardware device or software that ensures that only a single signal will be acted upon for a single opening or closing of a contact.”source
In Simple Term,
debouncing is a programming technique to delay the execution Of Code.
Why We Need Debouncing ?
If you run heavy time-consuming operations so often which does the same thing that decreases performance significantly. to prevent such situations we use a technique called debouncing. where we only execute code if another call doesn’t occur in a given time. means delaying execution if another execution request occurs.
Example To Implement Debouncing
Simple Explanation OF Above Example
In the above example no matter how many times you click the button HeavyTask function will only be executed after 500 milliseconds after the last click or the difference between two clicks is more than 500 seconds.
Here we ensure that if the button is clicked we will execute the HeavyTask function after 500 milliseconds but in meantime again button is clicked we cancel HeavyTask execution & call the HeavyTask function after 500 milliseconds. If Again button is clicked we repeat the above.
When To Use Debounceing Or Use Cases For Debouncing
- Input Validation
- Search Suggestions
- Auto Saving Functionality
- Event handling
Debounce Implementation In Different Libraries.
Implementing Debouncing in loadash.
Implementing Debouncing in underscore
Implementing Debouncing in jquery
Hey, readers Congratulation you just learnt debouncing & its use. I hope you like this article. if you have any doubt, suggestions or feedback feel free to comment below.