Merge pull request #35006 from sagarvora/debounce-flush-and-cancel
feat: cancel/flush debounced timeout
This commit is contained in:
commit
9c022f7f58
1 changed files with 29 additions and 8 deletions
|
|
@ -883,19 +883,40 @@ Object.assign(frappe.utils, {
|
|||
};
|
||||
},
|
||||
debounce: function (func, wait, immediate) {
|
||||
var timeout;
|
||||
return function () {
|
||||
var context = this,
|
||||
args = arguments;
|
||||
var later = function () {
|
||||
timeout = null;
|
||||
if (!immediate) func.apply(context, args);
|
||||
};
|
||||
var timeout, context, args;
|
||||
|
||||
var later = function () {
|
||||
timeout = null;
|
||||
if (!immediate) func.apply(context, args);
|
||||
};
|
||||
|
||||
var debounced = function () {
|
||||
context = this;
|
||||
args = arguments;
|
||||
var callNow = immediate && !timeout;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, wait);
|
||||
if (callNow) func.apply(context, args);
|
||||
};
|
||||
|
||||
debounced.cancel = function () {
|
||||
if (!timeout) return false;
|
||||
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
return true;
|
||||
};
|
||||
|
||||
debounced.flush = function () {
|
||||
if (!timeout) return false;
|
||||
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
func.apply(context, args);
|
||||
return true;
|
||||
};
|
||||
|
||||
return debounced;
|
||||
},
|
||||
get_form_link: function (
|
||||
doctype,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue