mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-13 20:37:48 +00:00
committed by
John-David Dalton
parent
f5ea579db3
commit
6ad829fa90
@@ -51,6 +51,9 @@ import isObject from './isObject.js'
|
|||||||
*
|
*
|
||||||
* // Cancel the trailing debounced invocation.
|
* // Cancel the trailing debounced invocation.
|
||||||
* jQuery(window).on('popstate', debounced.cancel)
|
* jQuery(window).on('popstate', debounced.cancel)
|
||||||
|
*
|
||||||
|
* // Check for pending invocations.
|
||||||
|
* const status = debounced.pending() ? "Pending…" : "Ready"
|
||||||
*/
|
*/
|
||||||
function debounce(func, wait, options) {
|
function debounce(func, wait, options) {
|
||||||
let lastArgs,
|
let lastArgs,
|
||||||
@@ -148,6 +151,10 @@ function debounce(func, wait, options) {
|
|||||||
function flush() {
|
function flush() {
|
||||||
return timerId === undefined ? result : trailingEdge(Date.now())
|
return timerId === undefined ? result : trailingEdge(Date.now())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pending() {
|
||||||
|
return timerId !== undefined
|
||||||
|
}
|
||||||
|
|
||||||
function debounced(...args) {
|
function debounced(...args) {
|
||||||
const time = Date.now()
|
const time = Date.now()
|
||||||
@@ -174,6 +181,7 @@ function debounce(func, wait, options) {
|
|||||||
}
|
}
|
||||||
debounced.cancel = cancel
|
debounced.cancel = cancel
|
||||||
debounced.flush = flush
|
debounced.flush = flush
|
||||||
|
debounced.pending = pending
|
||||||
return debounced
|
return debounced
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user