From db4ec2ba2f324dd5ee18238e97f710cc393e892e Mon Sep 17 00:00:00 2001 From: Bruno Boi Date: Thu, 16 Feb 2023 14:02:27 +0000 Subject: [PATCH] [REM] web, web_editor: remove throttle function This function is deprecated as its behaviour is closer to "debounce". Furthermore, it is not covered by any tests. Only one usage has been found in the code base: - the VideoSelector component from web_editor This usage has been replaced by the "debounce" timing utility, which is appropriate considering what the code tries to do. Part-of: odoo/odoo#112913 --- addons/web/static/src/core/utils/timing.js | 27 ------------------- .../components/media_dialog/video_selector.js | 4 +-- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/addons/web/static/src/core/utils/timing.js b/addons/web/static/src/core/utils/timing.js index 6c9d313642a..d68965f836f 100644 --- a/addons/web/static/src/core/utils/timing.js +++ b/addons/web/static/src/core/utils/timing.js @@ -53,33 +53,6 @@ export function throttleForAnimation(func) { ); } -/** - * Returns a function, that, as long as it continues to be invoked, will be - * triggered every N milliseconds. - * - * @deprecated this function has behaviour that is unexpected considering its - * name, prefer _.throttle until this function is rewritten - * @param {Function} func - * @param {number} delay - * @returns {Function} - */ -export function throttle(func, delay) { - let waiting = false; - const funcName = func.name ? func.name + " (throttle)" : "throttle"; - return { - [funcName](...args) { - const context = this; - if (!waiting) { - waiting = true; - browser.setTimeout(function () { - waiting = false; - func.call(context, ...args); - }, delay); - } - }, - }[funcName]; -} - /** * Creates and returns a new debounced version of the passed function (func) * which will postpone its execution until after 'delay' milliseconds diff --git a/addons/web_editor/static/src/components/media_dialog/video_selector.js b/addons/web_editor/static/src/components/media_dialog/video_selector.js index ed998c0e137..d4d474730d1 100644 --- a/addons/web_editor/static/src/components/media_dialog/video_selector.js +++ b/addons/web_editor/static/src/components/media_dialog/video_selector.js @@ -1,7 +1,7 @@ /** @odoo-module */ import { useService } from '@web/core/utils/hooks'; -import { throttle } from '@web/core/utils/timing'; +import { debounce } from '@web/core/utils/timing'; import { qweb } from 'web.core'; import { Component, useState, useRef, onMounted, onWillStart } from "@odoo/owl"; @@ -98,7 +98,7 @@ export class VideoSelector extends Component { })); }); - this.onChangeUrl = throttle((ev) => this.updateVideo(ev.target.value), 500); + this.onChangeUrl = debounce((ev) => this.updateVideo(ev.target.value), 500); } get shownOptions() {