@trengo/axios-progress-bar
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -117,8 +117,24 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
config.delay = config.delay !== undefined ? config.delay : 200; | ||
config.autoStart = config.autoStart !== undefined ? config.autoStart : true; | ||
var isStarted = false; | ||
var start = function start() { | ||
_nprogress2.default.start(); | ||
isStarted = true; | ||
}; | ||
var done = function done(force) { | ||
setTimeout(function () { | ||
isStarted = false; | ||
_nprogress2.default.done(force); | ||
}, config.delay); | ||
}; | ||
var setupStartProgress = function setupStartProgress() { | ||
instance.interceptors.request.use(function (config) { | ||
instance.interceptors.request.use(function (axiosConfig) { | ||
requestsCounter++; | ||
_nprogress2.default.start(); | ||
return config; | ||
if (config.autoStart) { | ||
start(); | ||
} | ||
return axiosConfig; | ||
}); | ||
@@ -131,4 +147,6 @@ }; | ||
}; | ||
instance.defaults.onDownloadProgress = update; | ||
instance.defaults.onUploadProgress = update; | ||
if (isStarted) { | ||
instance.defaults.onDownloadProgress = update; | ||
instance.defaults.onUploadProgress = update; | ||
} | ||
}; | ||
@@ -139,5 +157,3 @@ | ||
if (--requestsCounter === 0) { | ||
setTimeout(function () { | ||
_nprogress2.default.done(); | ||
}, config.delay); | ||
done(); | ||
} | ||
@@ -149,5 +165,3 @@ return response; | ||
if (--requestsCounter === 0) { | ||
setTimeout(function () { | ||
_nprogress2.default.done(); | ||
}, config.delay); | ||
done(); | ||
} | ||
@@ -154,0 +168,0 @@ return Promise.reject(error); |
{ | ||
"name": "@trengo/axios-progress-bar", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "A fork. Slim progress bar (NProgress) for Web applications that use Axios library for HTTP requests.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -11,8 +11,24 @@ import 'nprogress/nprogress.css' | ||
config.delay = config.delay !== undefined ? config.delay : 200 | ||
config.autoStart = config.autoStart !== undefined ? config.autoStart : true | ||
let isStarted = false; | ||
const start = () => { | ||
NProgress.start() | ||
isStarted = true; | ||
} | ||
const done = (force) => { | ||
setTimeout(() => { | ||
isStarted = false; | ||
NProgress.done(force) | ||
}, config.delay); | ||
} | ||
const setupStartProgress = () => { | ||
instance.interceptors.request.use(config => { | ||
instance.interceptors.request.use(axiosConfig => { | ||
requestsCounter++ | ||
NProgress.start() | ||
return config | ||
if(config.autoStart) { | ||
start(); | ||
} | ||
return axiosConfig | ||
}) | ||
@@ -23,4 +39,6 @@ } | ||
const update = e => NProgress.inc(calculatePercentage(e.loaded, e.total)) | ||
instance.defaults.onDownloadProgress = update | ||
instance.defaults.onUploadProgress = update | ||
if(isStarted) { | ||
instance.defaults.onDownloadProgress = update | ||
instance.defaults.onUploadProgress = update | ||
} | ||
} | ||
@@ -31,3 +49,3 @@ | ||
if ((--requestsCounter) === 0) { | ||
setTimeout(() => {NProgress.done()}, config.delay); | ||
done(); | ||
} | ||
@@ -39,3 +57,3 @@ return response | ||
if ((--requestsCounter) === 0) { | ||
setTimeout(() => {NProgress.done()}, config.delay); | ||
done(); | ||
} | ||
@@ -42,0 +60,0 @@ return Promise.reject(error) |
Sorry, the diff of this file is not supported yet
39001
700