diff --git a/debounce.js b/debounce.js index b70a38621..5e27275a6 100644 --- a/debounce.js +++ b/debounce.js @@ -51,6 +51,9 @@ import isObject from './isObject.js' * * // Cancel the trailing debounced invocation. * jQuery(window).on('popstate', debounced.cancel) + * + * // Check for pending invocations. + * const status = debounced.pending() ? "Pending…" : "Ready" */ function debounce(func, wait, options) { let lastArgs, @@ -148,6 +151,10 @@ function debounce(func, wait, options) { function flush() { return timerId === undefined ? result : trailingEdge(Date.now()) } + + function pending() { + return timerId !== undefined + } function debounced(...args) { const time = Date.now() @@ -174,6 +181,7 @@ function debounce(func, wait, options) { } debounced.cancel = cancel debounced.flush = flush + debounced.pending = pending return debounced }