From abf0126ccb735914c771bbd488af46977bed2e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Mon, 21 Jun 2021 18:25:21 +0200 Subject: [PATCH] Add throttle mixin --- .../Private/Assets/js/mixins/useThrottle.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/mixins/useThrottle.js diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/mixins/useThrottle.js b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/mixins/useThrottle.js new file mode 100644 index 00000000..83f2c938 --- /dev/null +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/mixins/useThrottle.js @@ -0,0 +1,14 @@ +export const useThrottle = controller => { + Object.assign(controller, { + throttle: (callback, interval) => { + let enableCall = true + return (...args) => { + if (!enableCall) return + enableCall = false + callback.apply(this, args) + setTimeout(() => enableCall = true, interval) + } + } + }) +} +