Fauxton: Improvements to xhr cancellations
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/d2a0c46e Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/d2a0c46e Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/d2a0c46e Branch: refs/heads/2041-update-ibrowse Commit: d2a0c46e9475b14c85067e0139b3ecb166fa475a Parents: 4d89338 Author: Garren Smith <[email protected]> Authored: Mon Feb 10 15:53:10 2014 +0200 Committer: Garren Smith <[email protected]> Committed: Mon Feb 10 15:53:10 2014 +0200 ---------------------------------------------------------------------- src/fauxton/app/core/base.js | 1 + src/fauxton/app/core/couchdbSession.js | 6 +++--- src/fauxton/app/core/routeObject.js | 4 +++- src/fauxton/app/core/router.js | 6 +++--- src/fauxton/assets/js/plugins/backbone.fetch-cache.js | 8 ++++---- 5 files changed, 14 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/d2a0c46e/src/fauxton/app/core/base.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/core/base.js b/src/fauxton/app/core/base.js index 24b89cf..7cacf39 100644 --- a/src/fauxton/app/core/base.js +++ b/src/fauxton/app/core/base.js @@ -96,6 +96,7 @@ function(Backbone, LayoutManager, BackboneCache) { fetchPromise.progress(promise.resolveWith); // Fires when the cache hit happens fetchPromise.then(promise.resolveWith); // Fires after the AJAX call + promise.fail(fetchPromise.abort); return promise; } http://git-wip-us.apache.org/repos/asf/couchdb/blob/d2a0c46e/src/fauxton/app/core/couchdbSession.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/core/couchdbSession.js b/src/fauxton/app/core/couchdbSession.js index b70ddf3..c59a8fc 100644 --- a/src/fauxton/app/core/couchdbSession.js +++ b/src/fauxton/app/core/couchdbSession.js @@ -30,15 +30,15 @@ function (FauxtonAPI) { fetchUser: function (opt) { var that = this, options = opt || {}, - currentUser = this.user(), - fetch = this.fetchOnce; + currentUser = this.user(), + fetch = _.bind(this.fetchOnce, this); if (options.forceFetch) { fetch = this.fetch; Backbone.fetchCache.clearItem(_.result(this.url)); } - return this.fetch(opt).then(function () { + return fetch(opt).then(function () { var user = that.user(); // Notify anyone listening on these events that either a user has changed http://git-wip-us.apache.org/repos/asf/couchdb/blob/d2a0c46e/src/fauxton/app/core/routeObject.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/core/routeObject.js b/src/fauxton/app/core/routeObject.js index f3b8672..9f1067f 100644 --- a/src/fauxton/app/core/routeObject.js +++ b/src/fauxton/app/core/routeObject.js @@ -223,6 +223,7 @@ function(FauxtonAPI, Backbone) { _.each(this.views, function (view, selector) { view.remove(); delete this.views[selector]; + view = null; }, this); }, @@ -230,6 +231,7 @@ function(FauxtonAPI, Backbone) { if (_.isEmpty(promise)) { return; } if (!_.isArray(promise)) { + if (!promise.abort && !promise.reject) { return this._promises.push(promise); } @@ -250,7 +252,7 @@ function(FauxtonAPI, Backbone) { return promise.abort("Route change"); } - promise.reject(); + promise.reject && promise.reject(); }, this); this._promises = []; http://git-wip-us.apache.org/repos/asf/couchdb/blob/d2a0c46e/src/fauxton/app/core/router.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/core/router.js b/src/fauxton/app/core/router.js index cc1ca4f..bef4ced 100644 --- a/src/fauxton/app/core/router.js +++ b/src/fauxton/app/core/router.js @@ -59,13 +59,13 @@ function(FauxtonAPI, Auth, Backbone) { authPromise.then(function () { if (!that.activeRouteObject || !that.activeRouteObject.hasRoute(route)) { - if (that.activeRouteObject) { - that.activeRouteObject.cleanup(); - } + that.activeRouteObject && that.activeRouteObject.cleanup(); + that.activeRouteObject = new RouteObject(route, masterLayout, args); } var routeObject = that.activeRouteObject; + routeObject.rejectPromises(); routeObject.routeCallback(route, args); routeObject.renderWith(route, masterLayout, args); }, function () { http://git-wip-us.apache.org/repos/asf/couchdb/blob/d2a0c46e/src/fauxton/assets/js/plugins/backbone.fetch-cache.js ---------------------------------------------------------------------- diff --git a/src/fauxton/assets/js/plugins/backbone.fetch-cache.js b/src/fauxton/assets/js/plugins/backbone.fetch-cache.js index c86a8b9..4aa7676 100644 --- a/src/fauxton/assets/js/plugins/backbone.fetch-cache.js +++ b/src/fauxton/assets/js/plugins/backbone.fetch-cache.js @@ -192,7 +192,7 @@ } if (!opts.prefill) { - return deferred.promise(); + return deferred; } } @@ -206,7 +206,7 @@ .fail( _.bind(deferred.reject, this, this) ); // return a promise which provides the same methods as a jqXHR object - return deferred.promise(); + return deferred; }; // Override Model.prototype.sync and try to clear cache items if it looks @@ -278,7 +278,7 @@ } if (!opts.prefill) { - return deferred.promise(); + return deferred; } } @@ -292,7 +292,7 @@ .fail( _.bind(deferred.reject, this, this) ); // return a promise which provides the same methods as a jqXHR object - return deferred.promise(); + return deferred; }; // Prime the cache from localStorage on initialization
