diff options
| author | Misko Hevery | 2010-12-08 16:52:08 -0800 | 
|---|---|---|
| committer | Igor Minar | 2011-01-04 16:40:40 -0800 | 
| commit | d0270d92568e1b7c762b42a0ee0712b65d9acc5c (patch) | |
| tree | 2a0f0680e6f9713c8c7a2c01d50e7a97d8b01d11 | |
| parent | 5f080193cbc0d84676cf267adcdc6307fb601610 (diff) | |
| download | angular.js-d0270d92568e1b7c762b42a0ee0712b65d9acc5c.tar.bz2 | |
Remove many eager-publish services, lazy polling
- Browser now starts the poller on first call to addPollFn()
- Many services ($location, $cookies, $router) are no longer eager-publish. The result is that
  unless someone needs the $cookies, they will not cause the Browser to start polling for them.
| -rw-r--r-- | CHANGELOG.md | 7 | ||||
| -rw-r--r-- | example/personalLog/test/personalLogSpec.js | 2 | ||||
| -rw-r--r-- | src/AngularPublic.js | 9 | ||||
| -rw-r--r-- | src/Browser.js | 4 | ||||
| -rw-r--r-- | src/services.js | 6 | ||||
| -rw-r--r-- | test/ScenarioSpec.js | 4 | ||||
| -rw-r--r-- | test/servicesSpec.js | 4 | 
7 files changed, 28 insertions, 8 deletions
| diff --git a/CHANGELOG.md b/CHANGELOG.md index ed96f68d..b9227eb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@  # <angular/> 0.9.9 time-shift (in-progress) # +### Breaking changes + - Many of the services are now lazy created instead of 'eager-publish'. You can get these +   services back into the root scope by adding ng:init="$location = $inject('$location')" +   in your view. The services effected are: +   - $location +   - $route +   - $cookies  # <angular/> 0.9.8 astral-projection (2010-12-23) # diff --git a/example/personalLog/test/personalLogSpec.js b/example/personalLog/test/personalLogSpec.js index d3df1b64..8d8eef97 100644 --- a/example/personalLog/test/personalLogSpec.js +++ b/example/personalLog/test/personalLogSpec.js @@ -3,6 +3,8 @@ describe('example.personalLog.LogCtrl', function() {    function createNotesCtrl() {      var scope = angular.scope(); +    var inject = scope.$inject; +    scope.$cookies = inject('$cookies');      return scope.$new(example.personalLog.LogCtrl);    } diff --git a/src/AngularPublic.js b/src/AngularPublic.js index af572340..38325404 100644 --- a/src/AngularPublic.js +++ b/src/AngularPublic.js @@ -17,11 +17,16 @@ angularService('$browser', function($log){          XHR,          $log,          window.setTimeout); -    browserSingleton.startPoller(50, function(delay, fn){setTimeout(delay,fn);}); +    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; -}, {inject:['$log']}); +}, {$inject:['$log']});  extend(angular, {    'element': jqLite, diff --git a/src/Browser.js b/src/Browser.js index 94807a8c..4ab92f10 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -115,7 +115,9 @@ function Browser(location, document, head, XHR, $log, setTimeout) {     * @methodOf angular.service.$browser     */    self.poll = function() { -    foreach(pollFns, function(pollFn){ pollFn(); }); +    foreach(pollFns, function(pollFn){  +      pollFn(); +    });    };    /** diff --git a/src/services.js b/src/services.js index 36c43564..5356d612 100644 --- a/src/services.js +++ b/src/services.js @@ -295,7 +295,7 @@ angularServiceInject("$location", function(browser) {      return h;    } -}, ['$browser'], EAGER_PUBLISHED); +}, ['$browser']);  /** @@ -678,7 +678,7 @@ angularServiceInject('$route', function(location) {    }    this.$watch(function(){return dirty + location.hash;}, updateRoute);    return $route; -}, ['$location'], EAGER_PUBLISHED); +}, ['$location']);  /**   * @workInProgress @@ -1124,7 +1124,7 @@ angularServiceInject('$cookies', function($browser) {        }      }    } -}, ['$browser'], EAGER_PUBLISHED); +}, ['$browser']);  /**   * @workInProgress diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js index 4a8b5e69..ec016635 100644 --- a/test/ScenarioSpec.js +++ b/test/ScenarioSpec.js @@ -42,7 +42,7 @@ describe("ScenarioSpec: Compilation", function(){      it("should have $ objects", function(){        scope = compile('<div></div>', {$config: {a:"b"}}); -      expect(scope.$get('$location')).toBeDefined(); +      expect(scope.$inject('$location')).toBeDefined();        expect(scope.$get('$eval')).toBeDefined();        expect(scope.$get('$config')).toBeDefined();        expect(scope.$get('$config.a')).toEqual("b"); @@ -53,7 +53,7 @@ describe("ScenarioSpec: Compilation", function(){      it("should take location object", function(){        var url = "http://server/#?book=moby";        scope = compile("<div>{{$location}}</div>"); -      var $location = scope.$location; +      var $location = scope.$inject('$location');        var $browser = scope.$inject('$browser');        expect($location.hashSearch.book).toBeUndefined();        $browser.setUrl(url); diff --git a/test/servicesSpec.js b/test/servicesSpec.js index bda7b47c..014acae4 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -14,6 +14,7 @@ describe("service", function(){      $xhrBulk = scope.$inject('$xhr.bulk');      $xhr = scope.$inject('$xhr');      $route = scope.$inject('$route'); +    scope.$location = inject('$location');    });    afterEach(function(){ @@ -202,6 +203,7 @@ describe("service", function(){      it('should update hash before any processing', function(){        scope = compile('<div>'); +      scope.$location = scope.$inject('$location');        var log = '';        scope.$watch('$location.hash', function(){          log += this.$location.hashPath + ';'; @@ -291,6 +293,7 @@ describe("service", function(){          this.log = '<init>';        }        scope = compile('<div></div>').$init(); +      scope.$location = scope.$inject('$location');        $route = scope.$inject('$route');        $route.when('/Book/:book/Chapter/:chapter', {controller: BookChapter, template:'Chapter.html'});        $route.when('/Blank'); @@ -604,6 +607,7 @@ describe("service", function(){        $browser = new MockBrowser();        $browser.cookieHash['preexisting'] = 'oldCookie';        scope = createScope(null, angularService, {$browser: $browser}); +      scope.$cookies = scope.$inject('$cookies');      }); | 
