/
TON618OFF
/
FinalPWHTML
Обзор
Документация
Войти
/
TON618OFF
/
FinalPWHTML
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
node_modules/axios/lib/helpers/throttle.js
35 строк
735 B
TON618OFF
не ну это ваще
23 июн 2024, 00:30
23 июн 2024, 00:30
e27ae20
Код
Авторство
О чём код?
'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() { const force = this === true; const now = Date.now(); if (force || now - timestamp > threshold) { if (timer) { clearTimeout(timer); timer = null; } timestamp = now; return fn.apply(null, arguments); } if (!timer) { timer = setTimeout(() => { timer = null; timestamp = Date.now(); return fn.apply(null, arguments); }, threshold - (now - timestamp)); } }; } export default throttle;