[IMP] web: expose immediate in useDebounced hook

Expose all debounced param in the hook.

closes odoo/odoo#106762

Signed-off-by: Géry Debongnie <ged@odoo.com>
This commit is contained in:
Didier (did)
2022-11-29 11:34:03 +01:00
parent e18a4324d3
commit c9ea3d0fa7
+4 -2
View File
@@ -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;
}