diff options
| author | Andres Ornelas | 2010-05-26 15:21:58 -0700 | 
|---|---|---|
| committer | Andres Ornelas | 2010-05-26 15:21:58 -0700 | 
| commit | aedf12f25e42877a302a99d906e6397bde01dcce (patch) | |
| tree | fd6ac4fe05668128937261093752b36c1bb02a6a /src/Browser.js | |
| parent | 0d41c86522ef912fe5bb7a02fd434080f9827c00 (diff) | |
| download | angular.js-aedf12f25e42877a302a99d906e6397bde01dcce.tar.bz2 | |
added outstanding request queue
Diffstat (limited to 'src/Browser.js')
| -rw-r--r-- | src/Browser.js | 31 | 
1 files changed, 29 insertions, 2 deletions
diff --git a/src/Browser.js b/src/Browser.js index 8abdbc61..0e265c0c 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -8,6 +8,7 @@ function Browser(location, document) {    this.urlListeners = [];    this.hoverListener = noop;    this.isMock = false; +  this.outstandingRequests = { count: 0, callbacks:[]};    this.XHR = window.XMLHttpRequest || function () {      try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e1) {} @@ -57,16 +58,42 @@ Browser.prototype = {        callback = post;        post = null;      } -    var xhr = new this.XHR(); +    var xhr = new this.XHR(), +        self = this;      xhr.open(method, url, true); +    this.outstandingRequests.count ++;      xhr.onreadystatechange = function() {        if (xhr.readyState == 4) { -        callback(xhr.status || 200, xhr.responseText); +        try { +          callback(xhr.status || 200, xhr.responseText); +        } finally { +          self.outstandingRequests.count--; +          self.processRequestCallbacks(); +        }        }      };      xhr.send(post || '');    }, +  processRequestCallbacks: function(){ +    if (this.outstandingRequests.count === 0) { +      while(this.outstandingRequests.callbacks.length) { +        try { +          this.outstandingRequests.callbacks.pop()(); +        } catch (e) { +        } +      } +    } +  }, + +  notifyWhenNoOutstandingRequests: function(callback){ +    if (this.outstandingRequests.count === 0) { +      callback(); +    } else { +      this.outstandingRequests.callbacks.push(callback); +    } +  }, +    watchUrl: function(fn){      this.urlListeners.push(fn);    },  | 
