2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-08 17:22:34 +03:00

fix(adapter): fix progress event emitting; (#6518)

This commit is contained in:
Dmitriy Mozgovoy
2024-08-01 16:59:58 +03:00
committed by GitHub
parent 85d4d0ea0a
commit e3c76fc9bd
10 changed files with 205 additions and 152 deletions
+16 -4
View File
@@ -1,7 +1,8 @@
import speedometer from "./speedometer.js";
import throttle from "./throttle.js";
import utils from "../utils.js";
export default (listener, isDownloadStream, freq = 3) => {
export const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
let bytesNotified = 0;
const _speedometer = speedometer(50, 250);
@@ -22,11 +23,22 @@ export default (listener, isDownloadStream, freq = 3) => {
rate: rate ? rate : undefined,
estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
event: e,
lengthComputable: total != null
lengthComputable: total != null,
[isDownloadStream ? 'download' : 'upload']: true
};
data[isDownloadStream ? 'download' : 'upload'] = true;
listener(data);
}, freq);
}
export const progressEventDecorator = (total, throttled) => {
const lengthComputable = total != null;
return [(loaded) => throttled[0]({
lengthComputable,
total,
loaded
}), throttled[1]];
}
export const asyncDecorator = (fn) => (...args) => utils.asap(() => fn(...args));