Moved progress-related functions to promises

This commit is contained in:
Marcin Kurczewski 2014-10-22 18:43:09 +02:00
parent 64743499b6
commit 8b217118af
2 changed files with 9 additions and 8 deletions

View file

@ -1,6 +1,6 @@
var App = App || {};
App.PresenterManager = function(jQuery, promise, topNavigationPresenter, keyboard, progress) {
App.PresenterManager = function(jQuery, promise, topNavigationPresenter, keyboard) {
var lastContentPresenter = null;
@ -15,8 +15,6 @@ App.PresenterManager = function(jQuery, promise, topNavigationPresenter, keyboar
}
function switchContentPresenter(presenter, args) {
progress.start();
if (lastContentPresenter === null || lastContentPresenter.name !== presenter.name) {
if (lastContentPresenter !== null && lastContentPresenter.deinit) {
lastContentPresenter.deinit();
@ -24,10 +22,10 @@ App.PresenterManager = function(jQuery, promise, topNavigationPresenter, keyboar
keyboard.reset();
topNavigationPresenter.changeTitle(null);
topNavigationPresenter.focus();
presenter.init.call(presenter, args, progress.done);
presenter.init.call(presenter, args, function() {});
lastContentPresenter = presenter;
} else if (lastContentPresenter.reinit) {
lastContentPresenter.reinit.call(lastContentPresenter, args, progress.done);
lastContentPresenter.reinit.call(lastContentPresenter, args, function() {});
}
}
@ -54,4 +52,4 @@ App.PresenterManager = function(jQuery, promise, topNavigationPresenter, keyboar
};
App.DI.registerSingleton('presenterManager', ['jQuery', 'promise', 'topNavigationPresenter', 'keyboard', 'progress'], App.PresenterManager);
App.DI.registerSingleton('presenterManager', ['jQuery', 'promise', 'topNavigationPresenter', 'keyboard'], App.PresenterManager);

View file

@ -1,6 +1,6 @@
var App = App || {};
App.Promise = function(_, jQuery) {
App.Promise = function(_, jQuery, progress) {
var active = [];
var promiseId = 0;
@ -30,6 +30,7 @@ App.Promise = function(_, jQuery) {
}
function wait() {
progress.start();
var promises = arguments;
var deferred = jQuery.Deferred();
return jQuery.when.apply(jQuery, promises)
@ -37,6 +38,8 @@ App.Promise = function(_, jQuery) {
return deferred.resolve.apply(deferred, arguments);
}).fail(function() {
return deferred.reject.apply(deferred, arguments);
}).always(function() {
progress.done();
});
}
@ -57,4 +60,4 @@ App.Promise = function(_, jQuery) {
};
App.DI.registerSingleton('promise', ['_', 'jQuery'], App.Promise);
App.DI.registerSingleton('promise', ['_', 'jQuery', 'progress'], App.Promise);