Fixed progress behavior when navigating too fast
This commit is contained in:
parent
5455106577
commit
619a0c0cc4
2 changed files with 25 additions and 10 deletions
|
@ -12,10 +12,16 @@ App.Presenters.ProgressPresenter = function(nprogress) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function done() {
|
function reset() {
|
||||||
nesting --;
|
nesting = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (nesting === 0) {
|
function done() {
|
||||||
|
if (nesting) {
|
||||||
|
nesting --;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nesting <= 0) {
|
||||||
nprogress.done();
|
nprogress.done();
|
||||||
} else {
|
} else {
|
||||||
nprogress.inc();
|
nprogress.inc();
|
||||||
|
@ -25,6 +31,7 @@ App.Presenters.ProgressPresenter = function(nprogress) {
|
||||||
return {
|
return {
|
||||||
start: start,
|
start: start,
|
||||||
done: done,
|
done: done,
|
||||||
|
reset: reset,
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,12 +10,23 @@ App.Promise = function(_, jQuery, progress) {
|
||||||
var promise = deferred.promise();
|
var promise = deferred.promise();
|
||||||
promise.promiseId = ++ promiseId;
|
promise.promiseId = ++ promiseId;
|
||||||
|
|
||||||
|
progress.start();
|
||||||
callback(function() {
|
callback(function() {
|
||||||
|
try {
|
||||||
deferred.resolve.apply(deferred, arguments);
|
deferred.resolve.apply(deferred, arguments);
|
||||||
active = _.without(active, promise.promiseId);
|
active = _.without(active, promise.promiseId);
|
||||||
|
progress.done();
|
||||||
|
} catch (e) {
|
||||||
|
progress.reset();
|
||||||
|
}
|
||||||
}, function() {
|
}, function() {
|
||||||
|
try {
|
||||||
deferred.reject.apply(deferred, arguments);
|
deferred.reject.apply(deferred, arguments);
|
||||||
active = _.without(active, promise.promiseId);
|
active = _.without(active, promise.promiseId);
|
||||||
|
progress.done();
|
||||||
|
} catch (e) {
|
||||||
|
progress.reset();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
active.push(promise.promiseId);
|
active.push(promise.promiseId);
|
||||||
|
@ -30,7 +41,6 @@ App.Promise = function(_, jQuery, progress) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function wait() {
|
function wait() {
|
||||||
progress.start();
|
|
||||||
var promises = arguments;
|
var promises = arguments;
|
||||||
var deferred = jQuery.Deferred();
|
var deferred = jQuery.Deferred();
|
||||||
return jQuery.when.apply(jQuery, promises)
|
return jQuery.when.apply(jQuery, promises)
|
||||||
|
@ -38,8 +48,6 @@ App.Promise = function(_, jQuery, progress) {
|
||||||
return deferred.resolve.apply(deferred, arguments);
|
return deferred.resolve.apply(deferred, arguments);
|
||||||
}).fail(function() {
|
}).fail(function() {
|
||||||
return deferred.reject.apply(deferred, arguments);
|
return deferred.reject.apply(deferred, arguments);
|
||||||
}).always(function() {
|
|
||||||
progress.done();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue