diff options
author | Garren Smith <garren.smith@gmail.com> | 2014-02-10 15:53:10 +0200 |
---|---|---|
committer | Garren Smith <garren.smith@gmail.com> | 2014-02-10 15:53:10 +0200 |
commit | d2a0c46e9475b14c85067e0139b3ecb166fa475a (patch) | |
tree | 8026f558fbf8820658732db0aff9a28f9d8bff06 | |
parent | 4d893387291ef4db1058a2f101bc0fd3c5064b17 (diff) | |
download | couchdb-d2a0c46e9475b14c85067e0139b3ecb166fa475a.tar.gz |
Fauxton: Improvements to xhr cancellations
-rw-r--r-- | src/fauxton/app/core/base.js | 1 | ||||
-rw-r--r-- | src/fauxton/app/core/couchdbSession.js | 6 | ||||
-rw-r--r-- | src/fauxton/app/core/routeObject.js | 4 | ||||
-rw-r--r-- | src/fauxton/app/core/router.js | 6 | ||||
-rw-r--r-- | src/fauxton/assets/js/plugins/backbone.fetch-cache.js | 8 |
5 files changed, 14 insertions, 11 deletions
diff --git a/src/fauxton/app/core/base.js b/src/fauxton/app/core/base.js index 24b89cf55..7cacf3918 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; } diff --git a/src/fauxton/app/core/couchdbSession.js b/src/fauxton/app/core/couchdbSession.js index b70ddf313..c59a8fc28 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 diff --git a/src/fauxton/app/core/routeObject.js b/src/fauxton/app/core/routeObject.js index f3b8672e0..9f1067f60 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 = []; diff --git a/src/fauxton/app/core/router.js b/src/fauxton/app/core/router.js index cc1ca4f64..bef4ced30 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 () { diff --git a/src/fauxton/assets/js/plugins/backbone.fetch-cache.js b/src/fauxton/assets/js/plugins/backbone.fetch-cache.js index c86a8b96f..4aa767660 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 |