mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
✨ Minor change in the debounce generator helper
This commit is contained in:
parent
5f90949c7d
commit
f047a9a54f
1 changed files with 5 additions and 9 deletions
|
@ -6,17 +6,14 @@ export const debounce = ( callback, delayMs ) => {
|
|||
|
||||
/**
|
||||
* Cancels any pending debounced execution.
|
||||
* @return {boolean} True if a pending execution was cancelled, false otherwise.
|
||||
*/
|
||||
const cancel = () => {
|
||||
if ( ! state.timeoutId ) {
|
||||
return false;
|
||||
if ( state.timeoutId ) {
|
||||
window.clearTimeout( state.timeoutId );
|
||||
}
|
||||
|
||||
window.clearTimeout( state.timeoutId );
|
||||
state.timeoutId = null;
|
||||
state.args = null;
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -24,14 +21,13 @@ export const debounce = ( callback, delayMs ) => {
|
|||
* @return {void}
|
||||
*/
|
||||
const flush = () => {
|
||||
const args = state.args;
|
||||
|
||||
// If there's nothing pending, return early.
|
||||
if ( ! cancel() ) {
|
||||
if ( ! state.timeoutId ) {
|
||||
return;
|
||||
}
|
||||
|
||||
callback.apply( null, args || [] );
|
||||
callback.apply( null, state.args || [] );
|
||||
cancel();
|
||||
};
|
||||
|
||||
const debouncedFunc = ( ...args ) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue