Updated Branches: refs/heads/fauxton-xhr-abort [created] 155f6a769
Clean up active xhr Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/155f6a76 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/155f6a76 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/155f6a76 Branch: refs/heads/fauxton-xhr-abort Commit: 155f6a7697661240253044d25b97b03a0c9eec9c Parents: a52c20b Author: Garren Smith <[email protected]> Authored: Thu Dec 19 15:52:22 2013 +0200 Committer: Garren Smith <[email protected]> Committed: Thu Dec 19 15:52:22 2013 +0200 ---------------------------------------------------------------------- src/fauxton/app/api.js | 41 ++++++++++++++++++++++++++++++++++++++--- src/fauxton/app/router.js | 17 +---------------- 2 files changed, 39 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/155f6a76/src/fauxton/app/api.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/api.js b/src/fauxton/app/api.js index 751cdd2..c2518c8 100644 --- a/src/fauxton/app/api.js +++ b/src/fauxton/app/api.js @@ -290,6 +290,7 @@ function(app, Fauxton) { establish: function() {}, route: function() {}, roles: [], + _promises: [], initialize: function() {} }, { @@ -319,7 +320,9 @@ function(app, Fauxton) { } triggerBroadcast('beforeEstablish'); - FauxtonAPI.when(this.establish()).then(function(resp) { + var establishPromise = this.establish(); + this.addPromise(establishPromise); + FauxtonAPI.when(establishPromise).then(function(resp) { triggerBroadcast('afterEstablish'); _.each(routeObject.getViews(), function(view, selector) { if(view.hasRendered) { @@ -328,6 +331,8 @@ function(app, Fauxton) { } triggerBroadcast('beforeRender', view, selector); + var viewPromise = view.establish(); + routeObject.addPromise(viewPromise); FauxtonAPI.when(view.establish()).then(function(resp) { masterLayout.setView(selector, view); @@ -339,7 +344,7 @@ function(app, Fauxton) { reason: resp }; - if (resp) { + if (resp && resp.responseText) { var errorText = JSON.parse(resp.responseText).reason; FauxtonAPI.addNotification({ msg: 'An Error occurred: ' + errorText, @@ -352,7 +357,7 @@ function(app, Fauxton) { }); }.bind(this), function (resp) { - if (!resp) { return; } + if (!resp || !resp.responseText) { return; } FauxtonAPI.addNotification({ msg: 'An Error occurred' + JSON.parse(resp.responseText).reason, type: 'error' @@ -420,6 +425,36 @@ function(app, Fauxton) { }, this); }, + addPromise: function (promise) { + if (_.isEmpty(promise)) { return; } + + if (_.isArray(promise)) { + return _.each(promise, function (p) { + this._promises.push(p); + }, this); + } + + this._promises.push(promise); + }, + + cleanup: function () { + this.removeViews(); + this.rejectPromises(); + }, + + rejectPromises: function () { + _.each(this._promises, function (promise) { + if (promise.state() === "resolved") { return; } + if (promise.abort) { + //return promise.abort("Route change"); + } + + //promise.reject(); + }, this); + + this._promises = []; + }, + getRouteUrls: function () { return _.keys(this.get('routes')); }, http://git-wip-us.apache.org/repos/asf/couchdb/blob/155f6a76/src/fauxton/app/router.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/router.js b/src/fauxton/app/router.js index e3a1636..160f221 100644 --- a/src/fauxton/app/router.js +++ b/src/fauxton/app/router.js @@ -89,7 +89,7 @@ function(req, app, Initialize, FauxtonAPI, Fauxton, Layout, Databases, Documents authPromise.then(function () { if (!that.activeRouteObject || !that.activeRouteObject.hasRoute(route)) { if (that.activeRouteObject) { - that.activeRouteObject.removeViews(); + that.activeRouteObject.cleanup(); } that.activeRouteObject = new RouteObject(route, masterLayout, args); } @@ -122,21 +122,6 @@ function(req, app, Initialize, FauxtonAPI, Fauxton, Layout, Databases, Documents }, this); }, - /*setAddonHooks: function() { - _.each(LoadAddons.addons, function(module) { - // This is updates to views by the addon - if (module && module.hooks){ - _.each(module.hooks, function(callback, route){ - if (this.masterLayout.hooks[route]) { - this.masterLayout.hooks[route].push(callback); - } else { - this.masterLayout.hooks[route] = [callback]; - } - }, this); - } - }, this); - },*/ - initialize: function() { //TODO: It would be nice to handle this with a router this.navBar = app.navBar = new Fauxton.NavBar();
