Utilities
debounce
This function provides a way to delay callback execution or prevent overcalling a function until certain conditions are met.
Params
fn
: The callback function to be executed
ms
: Time(in milliseconds) to delay callback execution
Returns
A debounce version of the original callback function. This function can be treated like the original callback, except when called, the delay timer resets.
Examples
import { debounce } from '@adobe/elsie/ore/lib';
const debouncedLog = debounce(console.log, 500);
debouncedLog('Do not log this string');
// Wait 250ms
debouncedLog('Do not log this string'); // Resets delay timer
// Wait 250ms
debouncedLog('Do not log this string'); // Resets delay timer
// Wait 250ms
debouncedLog('Log this string'); // Resets delay timer
// Wait 500ms
// 'Log this string' is logged to the console and no other messages have been logged