From 6ad829fa90af199150b11ba1d3c944b648a39ce5 Mon Sep 17 00:00:00 2001 From: Christopher James Calo Date: Wed, 27 Sep 2017 10:43:46 -0400 Subject: [PATCH] Add pending() function to debounce and throttle to fix #3387 (#3388) --- debounce.js | 8 ++++++++ 1 file changed, 8 insertions(+) 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 }