Add pending() function to debounce and throttle to fix #3387 (#3388)

This commit is contained in:
Christopher James Calo
2017-09-27 10:43:46 -04:00
committed by John-David Dalton
parent f5ea579db3
commit 6ad829fa90

View File

@@ -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
}