From 8fcc76ad6d206cb98d6742764336503d322a5b4c Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 2 Jun 2022 23:25:59 +0200 Subject: [PATCH] fix debounce webpack --- libraries/lodash.debounce.js | 70 ------------------- src/public/app/services/debounce.js | 70 +++++++++++++++++++ src/public/app/widgets/type_widgets/canvas.js | 2 +- 3 files changed, 71 insertions(+), 71 deletions(-) delete mode 100644 libraries/lodash.debounce.js create mode 100644 src/public/app/services/debounce.js diff --git a/libraries/lodash.debounce.js b/libraries/lodash.debounce.js deleted file mode 100644 index 4dcbf96c9..000000000 --- a/libraries/lodash.debounce.js +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Returns a function, that, as long as it continues to be invoked, will not - * be triggered. The function will be called after it stops being called for - * N milliseconds. If `immediate` is passed, trigger the function on the - * leading edge, instead of the trailing. The function also has a property 'clear' - * that is a function which will clear the timer to prevent previously scheduled executions. - * - * @source underscore.js - * @see http://unscriptable.com/2009/03/20/debouncing-javascript-methods/ - * @param {Function} function to wrap - * @param {Number} timeout in ms (`100`) - * @param {Boolean} whether to execute at the beginning (`false`) - * @api public - */ -function debounce(func, wait_ms, immediate){ - var timeout, args, context, timestamp, result; - if (null == wait_ms) wait_ms = 100; - - function later() { - var last = Date.now() - timestamp; - - if (last < wait_ms && last >= 0) { - timeout = setTimeout(later, wait_ms - last); - } else { - timeout = null; - if (!immediate) { - result = func.apply(context, args); - context = args = null; - } - } - }; - - var debounced = function(){ - context = this; - args = arguments; - timestamp = Date.now(); - var callNow = immediate && !timeout; - if (!timeout) timeout = setTimeout(later, wait_ms); - if (callNow) { - result = func.apply(context, args); - context = args = null; - } - - return result; - }; - - debounced.clear = function() { - if (timeout) { - clearTimeout(timeout); - timeout = null; - } - }; - - debounced.flush = function() { - if (timeout) { - result = func.apply(context, args); - context = args = null; - - clearTimeout(timeout); - timeout = null; - } - }; - - return debounced; -}; - -// Adds compatibility for ES modules -debounce.debounce = debounce; - -export default debounce; diff --git a/src/public/app/services/debounce.js b/src/public/app/services/debounce.js new file mode 100644 index 000000000..e737bcd76 --- /dev/null +++ b/src/public/app/services/debounce.js @@ -0,0 +1,70 @@ +/** + * Returns a function, that, as long as it continues to be invoked, will not + * be triggered. The function will be called after it stops being called for + * N milliseconds. If `immediate` is passed, trigger the function on the + * leading edge, instead of the trailing. The function also has a property 'clear' + * that is a function which will clear the timer to prevent previously scheduled executions. + * + * @source underscore.js + * @see http://unscriptable.com/2009/03/20/debouncing-javascript-methods/ + * @param {Function} function to wrap + * @param {Number} timeout in ms (`100`) + * @param {Boolean} whether to execute at the beginning (`false`) + * @api public + */ +function debounce(func, wait_ms, immediate){ + var timeout, args, context, timestamp, result; + if (null == wait_ms) wait_ms = 100; + + function later() { + var last = Date.now() - timestamp; + + if (last < wait_ms && last >= 0) { + timeout = setTimeout(later, wait_ms - last); + } else { + timeout = null; + if (!immediate) { + result = func.apply(context, args); + context = args = null; + } + } + }; + + var debounced = function(){ + context = this; + args = arguments; + timestamp = Date.now(); + var callNow = immediate && !timeout; + if (!timeout) timeout = setTimeout(later, wait_ms); + if (callNow) { + result = func.apply(context, args); + context = args = null; + } + + return result; + }; + + debounced.clear = function() { + if (timeout) { + clearTimeout(timeout); + timeout = null; + } + }; + + debounced.flush = function() { + if (timeout) { + result = func.apply(context, args); + context = args = null; + + clearTimeout(timeout); + timeout = null; + } + }; + + return debounced; +}; + +// Adds compatibility for ES modules +debounce.debounce = debounce; + +export default debounce; diff --git a/src/public/app/widgets/type_widgets/canvas.js b/src/public/app/widgets/type_widgets/canvas.js index 0885e54ac..e713e3776 100644 --- a/src/public/app/widgets/type_widgets/canvas.js +++ b/src/public/app/widgets/type_widgets/canvas.js @@ -2,7 +2,7 @@ import libraryLoader from "../../services/library_loader.js"; import TypeWidget from "./type_widget.js"; import utils from '../../services/utils.js'; import froca from "../../services/froca.js"; -import debounce from "../../../libraries/lodash.debounce.js"; +import debounce from "../../services/debounce.js"; const {sleep} = utils;