You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2013/12/19 15:01:10 UTC
git commit: updated refs/heads/fauxton-xhr-abort to e3f1a25
Updated Branches:
refs/heads/fauxton-xhr-abort 155f6a769 -> e3f1a2521 (forced update)
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/e3f1a252
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/e3f1a252
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/e3f1a252
Branch: refs/heads/fauxton-xhr-abort
Commit: e3f1a2521987ab148d72cbb590d004dbd2a0ed5c
Parents: a52c20b
Author: Garren Smith <ga...@gmail.com>
Authored: Thu Dec 19 15:52:22 2013 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Thu Dec 19 15:58: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/e3f1a252/src/fauxton/app/api.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/api.js b/src/fauxton/app/api.js
index 751cdd2..7812baf 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/e3f1a252/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();