mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
feat(adapter): add fetch adapter; (#6371)
This commit is contained in:
@@ -10,7 +10,9 @@ function throttle(fn, freq) {
|
||||
let timestamp = 0;
|
||||
const threshold = 1000 / freq;
|
||||
let timer = null;
|
||||
return function throttled(force, args) {
|
||||
return function throttled() {
|
||||
const force = this === true;
|
||||
|
||||
const now = Date.now();
|
||||
if (force || now - timestamp > threshold) {
|
||||
if (timer) {
|
||||
@@ -18,13 +20,13 @@ function throttle(fn, freq) {
|
||||
timer = null;
|
||||
}
|
||||
timestamp = now;
|
||||
return fn.apply(null, args);
|
||||
return fn.apply(null, arguments);
|
||||
}
|
||||
if (!timer) {
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
timestamp = Date.now();
|
||||
return fn.apply(null, args);
|
||||
return fn.apply(null, arguments);
|
||||
}, threshold - (now - timestamp));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user