couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [18/52] [abbrv] fauxton commit: updated refs/heads/import-master to d11b90b
Date Wed, 12 Feb 2014 06:20:12 GMT
Clean up active xhr


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/015829c2
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/015829c2
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/015829c2

Branch: refs/heads/import-master
Commit: 015829c25213066b37597cf9bc200e7099939986
Parents: 921ff62
Author: Garren Smith <garren.smith@gmail.com>
Authored: Thu Dec 19 15:52:22 2013 +0200
Committer: suelockwood <deathbear@apache.org>
Committed: Tue Jan 14 10:45:55 2014 -0500

----------------------------------------------------------------------
 app/api.js    | 41 ++++++++++++++++++++++++++++++++++++++---
 app/router.js |  2 +-
 2 files changed, 39 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/015829c2/app/api.js
----------------------------------------------------------------------
diff --git a/app/api.js b/app/api.js
index f423ef5..6d450de 100644
--- a/app/api.js
+++ b/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,
@@ -353,7 +358,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',
@@ -422,6 +427,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-fauxton/blob/015829c2/app/router.js
----------------------------------------------------------------------
diff --git a/app/router.js b/app/router.js
index 7cf69ad..89c60cf 100644
--- a/app/router.js
+++ b/app/router.js
@@ -76,7 +76,7 @@ function(req, app, Initialize, FauxtonAPI, Fauxton, Layout, LoadAddons)
{
           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);
             }


Mime
View raw message