Skip to main content

Debounce Helper

Efficiently execute a function but not more often than the given wait time (in milliseconds) limits to. Use the immediate flag to indicate if the function should be executed before or after the wait time.

import { debounce } from 'eyeson';

debounce(func, wait, immediate); // debounce function

Use this method to enhance performance on several executions. Let's say you want to act on a browser window resize, simply listening on the event may execute a lot. When wrapping your handler by debounce you may execute it only every 100ms, still providing a real-time-feeling for your user but with much better performance and smoother look and feel.

For example:

window.addEventListener('resize', debounce(() => {
// execute 100ms after the last resize event
}), 100);