fix issue that caused delayed and broken resizing

This commit is contained in:
Jeff Nusz 2017-03-14 16:29:17 -07:00
parent d5b6178e33
commit dc6b6a388a
2 changed files with 7 additions and 5 deletions

View File

@ -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 * Mark objects for saving. The order of these objects cannot change as

View File

@ -88,8 +88,9 @@ const Common = {
setTimeout(fnc, 0); setTimeout(fnc, 0);
}, },
// call the function immediately, but wait until threshold passes to allow it to be called again // if the function is called repeatedly, wait until threshold passes until we execute the function
debounce: function(func, threshold) { debounce: function(func, threshold, callImmediately) {
let timeout; let timeout;
return function() { return function() {
@ -97,14 +98,15 @@ const Common = {
const args = arguments; const args = arguments;
function delayed() { function delayed() {
timeout = null; timeout = null;
if (!callImmediately) func.apply(obj, args);
} }
const allowCall = !timeout; const callNow = callImmediately || !timeout;
clearTimeout(timeout); clearTimeout(timeout);
timeout = setTimeout(delayed, threshold); timeout = setTimeout(delayed, threshold);
if (allowCall) { if (callNow) {
func.apply(obj, args); func.apply(obj, args);
} }
}; };