From 3d1cd02f27518f1a04374c7c8320cd5d82ede6e9 Mon Sep 17 00:00:00 2001 From: Minteck Date: Thu, 23 Feb 2023 19:34:56 +0100 Subject: Updated 40 files, added 37 files, deleted 1103 files and renamed 3905 files (automated) --- .../node_modules/axios/lib/helpers/throttle.js | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 includes/external/school/node_modules/axios/lib/helpers/throttle.js (limited to 'includes/external/school/node_modules/axios/lib/helpers/throttle.js') diff --git a/includes/external/school/node_modules/axios/lib/helpers/throttle.js b/includes/external/school/node_modules/axios/lib/helpers/throttle.js new file mode 100644 index 0000000..6969df1 --- /dev/null +++ b/includes/external/school/node_modules/axios/lib/helpers/throttle.js @@ -0,0 +1,33 @@ +'use strict'; + +/** + * Throttle decorator + * @param {Function} fn + * @param {Number} freq + * @return {Function} + */ +function throttle(fn, freq) { + let timestamp = 0; + const threshold = 1000 / freq; + let timer = null; + return function throttled(force, args) { + const now = Date.now(); + if (force || now - timestamp > threshold) { + if (timer) { + clearTimeout(timer); + timer = null; + } + timestamp = now; + return fn.apply(null, args); + } + if (!timer) { + timer = setTimeout(() => { + timer = null; + timestamp = Date.now(); + return fn.apply(null, args); + }, threshold - (now - timestamp)); + } + }; +} + +export default throttle; -- cgit