Fixed progress behavior when navigating too fast

This commit is contained in:
Marcin Kurczewski 2014-10-22 19:09:25 +02:00
parent 5455106577
commit 619a0c0cc4
2 changed files with 25 additions and 10 deletions

View file

@ -12,10 +12,16 @@ App.Presenters.ProgressPresenter = function(nprogress) {
}
}
function done() {
nesting --;
function reset() {
nesting = 0;
}
if (nesting === 0) {
function done() {
if (nesting) {
nesting --;
}
if (nesting <= 0) {
nprogress.done();
} else {
nprogress.inc();
@ -25,6 +31,7 @@ App.Presenters.ProgressPresenter = function(nprogress) {
return {
start: start,
done: done,
reset: reset,
};
};

View file

@ -10,12 +10,23 @@ App.Promise = function(_, jQuery, progress) {
var promise = deferred.promise();
promise.promiseId = ++ promiseId;
progress.start();
callback(function() {
deferred.resolve.apply(deferred, arguments);
active = _.without(active, promise.promiseId);
try {
deferred.resolve.apply(deferred, arguments);
active = _.without(active, promise.promiseId);
progress.done();
} catch (e) {
progress.reset();
}
}, function() {
deferred.reject.apply(deferred, arguments);
active = _.without(active, promise.promiseId);
try {
deferred.reject.apply(deferred, arguments);
active = _.without(active, promise.promiseId);
progress.done();
} catch (e) {
progress.reset();
}
});
active.push(promise.promiseId);
@ -30,7 +41,6 @@ App.Promise = function(_, jQuery, progress) {
}
function wait() {
progress.start();
var promises = arguments;
var deferred = jQuery.Deferred();
return jQuery.when.apply(jQuery, promises)
@ -38,8 +48,6 @@ App.Promise = function(_, jQuery, progress) {
return deferred.resolve.apply(deferred, arguments);
}).fail(function() {
return deferred.reject.apply(deferred, arguments);
}).always(function() {
progress.done();
});
}