Merge pull request #35006 from sagarvora/debounce-flush-and-cancel

feat: cancel/flush debounced timeout
This commit is contained in:
Sagar Vora 2025-12-02 09:52:38 +05:30 committed by GitHub
commit 9c022f7f58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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