From c9ea3d0fa70cbad47e4c775041e2a53dae44083c Mon Sep 17 00:00:00 2001 From: "Didier (did)" Date: Tue, 29 Nov 2022 08:25:56 +0000 Subject: [PATCH] [IMP] web: expose immediate in useDebounced hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Expose all debounced param in the hook. closes odoo/odoo#106762 Signed-off-by: Géry Debongnie --- addons/web/static/src/core/utils/timing.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/core/utils/timing.js b/addons/web/static/src/core/utils/timing.js index 86cbaeb4684..60da6e97e19 100644 --- a/addons/web/static/src/core/utils/timing.js +++ b/addons/web/static/src/core/utils/timing.js @@ -119,11 +119,13 @@ export function debounce(func, delay, immediate = false) { * @template {Function} T * @param {T} callback * @param {number | "animationFrame"} delay + * @param {boolean} [immediate=false] whether the function should be called on + * the leading edge instead of the trailing edge. * @returns {T & { cancel: () => void }} */ -export function useDebounced(callback, delay) { +export function useDebounced(callback, delay, immediate = false) { const component = useComponent(); - const debounced = debounce(callback.bind(component), delay); + const debounced = debounce(callback.bind(component), delay, immediate); onWillUnmount(() => debounced.cancel()); return debounced; }