Fixed top navigation loading glitch

A race condition occurred - router could execute promise.abortAll()
even when top navigation didn't fully load. This caused top navigation
presenter to throw "broken promise" error, which is reserved for
promises made after core modules have been loaded.
This commit is contained in:
Marcin Kurczewski 2014-10-05 16:30:26 +02:00
parent 640b66a324
commit 6e09f90251
2 changed files with 8 additions and 6 deletions

View file

@ -2,9 +2,9 @@ var App = App || {};
App.Bootstrap = function(auth, router, util, promise, presenterManager) { App.Bootstrap = function(auth, router, util, promise, presenterManager) {
presenterManager.init(); promise.wait(
auth.tryLoginFromCookie(),
promise.wait(auth.tryLoginFromCookie()) presenterManager.init())
.then(startRouting) .then(startRouting)
.fail(function(error) { .fail(function(error) {
promise.wait(auth.loginAnonymous()) promise.wait(auth.loginAnonymous())

View file

@ -1,14 +1,16 @@
var App = App || {}; var App = App || {};
App.PresenterManager = function(jQuery, topNavigationPresenter, keyboard) { App.PresenterManager = function(jQuery, promise, topNavigationPresenter, keyboard) {
var lastContentPresenter = null; var lastContentPresenter = null;
var $spinner; var $spinner;
var spinnerTimeout; var spinnerTimeout;
function init() { function init() {
initPresenter(topNavigationPresenter, [], function() {});
$spinner = jQuery('body').find('#wait'); $spinner = jQuery('body').find('#wait');
return promise.make(function(resolve, reject) {
initPresenter(topNavigationPresenter, [], resolve);
});
} }
function initPresenter(presenter, args, loaded) { function initPresenter(presenter, args, loaded) {
@ -72,4 +74,4 @@ App.PresenterManager = function(jQuery, topNavigationPresenter, keyboard) {
}; };
App.DI.registerSingleton('presenterManager', ['jQuery', 'topNavigationPresenter', 'keyboard'], App.PresenterManager); App.DI.registerSingleton('presenterManager', ['jQuery', 'promise', 'topNavigationPresenter', 'keyboard'], App.PresenterManager);