From dc6b6a388a93241f7ebb4fe56f3714a951b921f2 Mon Sep 17 00:00:00 2001 From: Jeff Nusz Date: Tue, 14 Mar 2017 16:29:17 -0700 Subject: [PATCH] fix issue that caused delayed and broken resizing --- src/dat/gui/GUI.js | 2 +- src/dat/utils/common.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/dat/gui/GUI.js b/src/dat/gui/GUI.js index e037111..d9955ca 100644 --- a/src/dat/gui/GUI.js +++ b/src/dat/gui/GUI.js @@ -605,7 +605,7 @@ common.extend( } }, - onResizeDebounced: common.debounce(function() { this.onResize(); }, 200), + onResizeDebounced: common.debounce(function() { this.onResize(); }, 50), /** * Mark objects for saving. The order of these objects cannot change as diff --git a/src/dat/utils/common.js b/src/dat/utils/common.js index 1a952ae..8a5283b 100644 --- a/src/dat/utils/common.js +++ b/src/dat/utils/common.js @@ -88,8 +88,9 @@ const Common = { setTimeout(fnc, 0); }, - // call the function immediately, but wait until threshold passes to allow it to be called again - debounce: function(func, threshold) { + // if the function is called repeatedly, wait until threshold passes until we execute the function + debounce: function(func, threshold, callImmediately) { + let timeout; return function() { @@ -97,14 +98,15 @@ const Common = { const args = arguments; function delayed() { timeout = null; + if (!callImmediately) func.apply(obj, args); } - const allowCall = !timeout; + const callNow = callImmediately || !timeout; clearTimeout(timeout); timeout = setTimeout(delayed, threshold); - if (allowCall) { + if (callNow) { func.apply(obj, args); } };