Commits

Anton Shestakov committed 8a7155a

Abort all requests on workspace change.

Comments (1)

  1. Anton Shestakov author

    Well, obviously, not ALL requests. Only those stored in fruitbar.xhrs, which are fetch requests for projects and tasks. Everything else, such as update/delete requests are not stored there and therefore not aborted.

Files changed (1)

         }
     });
     
+    fruitbar.xhrs = [];
+    fruitbar.xhrs.abort = function() {
+        _(this).each(function(xhr) {
+            xhr.abort();
+        });
+        
+        this.length = 0;
+    };
+    
     fruitbar.on('workspace', function(workspace) {
+        this.xhrs.abort();
+        
         this.tasks.url = '/' + encodeURIComponent(workspace) + '/tasks/';
         this.projects.url = '/' + encodeURIComponent(workspace) + '/projects/';
         
-        this.tasks.fetch();
-        this.projects.fetch();
+        this.xhrs.push(this.tasks.fetch(), this.projects.fetch());
     });
     
     fruitbar.once('workspace', function() {
-        window.setInterval(function() {fruitbar.projects.fetch({update: true});}, 60000);
-        window.setInterval(function() {fruitbar.tasks.fetch({update: true});}, 60000);
+        window.setInterval(function() {
+            fruitbar.xhrs.push(fruitbar.tasks.fetch({update: true}));
+        }, 60000);
+        window.setInterval(function() {
+            fruitbar.xhrs.push(fruitbar.projects.fetch({update: true}));
+        }, 60000);
     });
     
     Backbone.history.start();