From ec7c10c99b8a6fa071ebc7469545abfe84b16350 Mon Sep 17 00:00:00 2001 From: Leonard Kim Date: Mon, 21 Aug 2017 17:15:40 -0700 Subject: [PATCH] ref(toolbar): replace custom debounce with lodash throttle The current custom debounce function sets a timeout and ensures additional calls are not executed while the timeout is pending. Regulating the call of a function while also ensuring it gets called at a certain time is a throttle. --- modules/UI/UI.js | 9 +++++---- modules/util/helpers.js | 30 ------------------------------ 2 files changed, 5 insertions(+), 34 deletions(-) diff --git a/modules/UI/UI.js b/modules/UI/UI.js index 4f9823687..f31986859 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.js @@ -4,6 +4,8 @@ const logger = require("jitsi-meet-logger").getLogger(__filename); var UI = {}; +import _ from 'lodash'; + import Chat from "./side_pannels/chat/Chat"; import SidePanels from "./side_pannels/SidePanels"; import Avatar from "./avatar/Avatar"; @@ -20,7 +22,6 @@ import Filmstrip from "./videolayout/Filmstrip"; import SettingsMenu from "./side_pannels/settings/SettingsMenu"; import Profile from "./side_pannels/profile/Profile"; import Settings from "./../settings/Settings"; -import { debounce } from "../util/helpers"; import { updateDeviceList } from '../../react/features/base/devices'; import { @@ -278,13 +279,13 @@ UI.start = function () { sharedVideoManager = new SharedVideoManager(eventEmitter); if (!interfaceConfig.filmStripOnly) { - let debouncedShowToolbar - = debounce( + let throttledShowToolbar + = _.throttle( () => UI.showToolbar(), 100, { leading: true, trailing: false }); - $("#videoconference_page").mousemove(debouncedShowToolbar); + $("#videoconference_page").mousemove(throttledShowToolbar); // Initialise the recording module. if (config.enableRecording) { diff --git a/modules/util/helpers.js b/modules/util/helpers.js index 39d173d49..c429e74f5 100644 --- a/modules/util/helpers.js +++ b/modules/util/helpers.js @@ -16,36 +16,6 @@ export function createDeferred() { return deferred; } -/** - * Creates a debounced function that delays invoking func until after wait - * milliseconds have elapsed since the last time the debounced function was - * invoked. - * - * @param fn - * @param wait - * @param options - * @returns {function(...[*])} - */ -export function debounce(fn, wait = 0, options = {}) { - const leading = options.leading || false; - const trailing - = (typeof options.trailing === 'undefined') || options.trailing; - let called = false; - - return (...args) => { - if (!called) { - leading && fn(...args); - - setTimeout(() => { - called = false; - trailing && fn(...args); - }, wait); - - called = true; - } - }; -} - /** * Returns the namespace for all global variables, functions, etc that we need. *