diff options
| author | Vojta Jina | 2011-06-01 17:38:25 +0200 |
|---|---|---|
| committer | Igor Minar | 2011-06-02 10:50:43 -0700 |
| commit | dad26037521ff681f9a3c3d4a9bebf14fb8e38cc (patch) | |
| tree | 15b5a83a6fd7731a5c50259198591878915c86fd /src | |
| parent | 50076b571da522cf6d2cb92c28519694727e9c31 (diff) | |
| download | angular.js-dad26037521ff681f9a3c3d4a9bebf14fb8e38cc.tar.bz2 | |
Refactor $browser's lazy start polling
+ unit tests
Diffstat (limited to 'src')
| -rw-r--r-- | src/AngularPublic.js | 6 | ||||
| -rw-r--r-- | src/Browser.js | 9 |
2 files changed, 6 insertions, 9 deletions
diff --git a/src/AngularPublic.js b/src/AngularPublic.js index b62483f8..cc901d6d 100644 --- a/src/AngularPublic.js +++ b/src/AngularPublic.js @@ -12,12 +12,6 @@ angularService('$browser', function($log){ if (!browserSingleton) { browserSingleton = new Browser(window, jqLite(window.document), jqLite(window.document.body), XHR, $log); - var addPollFn = browserSingleton.addPollFn; - browserSingleton.addPollFn = function(){ - browserSingleton.addPollFn = addPollFn; - browserSingleton.startPoller(100, function(delay, fn){setTimeout(delay,fn);}); - return addPollFn.apply(browserSingleton, arguments); - }; browserSingleton.bind(); } return browserSingleton; diff --git a/src/Browser.js b/src/Browser.js index 80cabe02..052ea59f 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -141,7 +141,8 @@ function Browser(window, document, body, XHR, $log) { ////////////////////////////////////////////////////////////// // Poll Watcher API ////////////////////////////////////////////////////////////// - var pollFns = []; + var pollFns = [], + pollTimeout; /** * @workInProgress @@ -162,11 +163,13 @@ function Browser(window, document, body, XHR, $log) { * @param {function()} fn Poll function to add * * @description - * Adds a function to the list of functions that poller periodically executes + * Adds a function to the list of functions that poller periodically executes, + * and starts polling if not started yet. * * @returns {function()} the added function */ self.addPollFn = function(fn) { + if (!pollTimeout) self.startPoller(100, setTimeout); pollFns.push(fn); return fn; }; @@ -187,7 +190,7 @@ function Browser(window, document, body, XHR, $log) { self.startPoller = function(interval, setTimeout) { (function check(){ self.poll(); - setTimeout(check, interval); + pollTimeout = setTimeout(check, interval); })(); }; |
