Skip to content

Commit d0270d9

Browse files
mheveryIgorMinar
authored andcommitted
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.
1 parent 5f08019 commit d0270d9

7 files changed

Lines changed: 28 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# <angular/> 0.9.9 time-shift (in-progress) #
22

3+
### Breaking changes
4+
- Many of the services are now lazy created instead of 'eager-publish'. You can get these
5+
services back into the root scope by adding ng:init="$location = $inject('$location')"
6+
in your view. The services effected are:
7+
- $location
8+
- $route
9+
- $cookies
310

411

512
# <angular/> 0.9.8 astral-projection (2010-12-23) #

example/personalLog/test/personalLogSpec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ describe('example.personalLog.LogCtrl', function() {
33

44
function createNotesCtrl() {
55
var scope = angular.scope();
6+
var inject = scope.$inject;
7+
scope.$cookies = inject('$cookies');
68
return scope.$new(example.personalLog.LogCtrl);
79
}
810

src/AngularPublic.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@ angularService('$browser', function($log){
1717
XHR,
1818
$log,
1919
window.setTimeout);
20-
browserSingleton.startPoller(50, function(delay, fn){setTimeout(delay,fn);});
20+
var addPollFn = browserSingleton.addPollFn;
21+
browserSingleton.addPollFn = function(){
22+
browserSingleton.addPollFn = addPollFn;
23+
browserSingleton.startPoller(100, function(delay, fn){setTimeout(delay,fn);});
24+
return addPollFn.apply(browserSingleton, arguments);
25+
};
2126
browserSingleton.bind();
2227
}
2328
return browserSingleton;
24-
}, {inject:['$log']});
29+
}, {$inject:['$log']});
2530

2631
extend(angular, {
2732
'element': jqLite,

src/Browser.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ function Browser(location, document, head, XHR, $log, setTimeout) {
115115
* @methodOf angular.service.$browser
116116
*/
117117
self.poll = function() {
118-
foreach(pollFns, function(pollFn){ pollFn(); });
118+
foreach(pollFns, function(pollFn){
119+
pollFn();
120+
});
119121
};
120122

121123
/**

src/services.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ angularServiceInject("$location", function(browser) {
295295

296296
return h;
297297
}
298-
}, ['$browser'], EAGER_PUBLISHED);
298+
}, ['$browser']);
299299

300300

301301
/**
@@ -678,7 +678,7 @@ angularServiceInject('$route', function(location) {
678678
}
679679
this.$watch(function(){return dirty + location.hash;}, updateRoute);
680680
return $route;
681-
}, ['$location'], EAGER_PUBLISHED);
681+
}, ['$location']);
682682

683683
/**
684684
* @workInProgress
@@ -1124,7 +1124,7 @@ angularServiceInject('$cookies', function($browser) {
11241124
}
11251125
}
11261126
}
1127-
}, ['$browser'], EAGER_PUBLISHED);
1127+
}, ['$browser']);
11281128

11291129
/**
11301130
* @workInProgress

test/ScenarioSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe("ScenarioSpec: Compilation", function(){
4242

4343
it("should have $ objects", function(){
4444
scope = compile('<div></div>', {$config: {a:"b"}});
45-
expect(scope.$get('$location')).toBeDefined();
45+
expect(scope.$inject('$location')).toBeDefined();
4646
expect(scope.$get('$eval')).toBeDefined();
4747
expect(scope.$get('$config')).toBeDefined();
4848
expect(scope.$get('$config.a')).toEqual("b");
@@ -53,7 +53,7 @@ describe("ScenarioSpec: Compilation", function(){
5353
it("should take location object", function(){
5454
var url = "http://server/#?book=moby";
5555
scope = compile("<div>{{$location}}</div>");
56-
var $location = scope.$location;
56+
var $location = scope.$inject('$location');
5757
var $browser = scope.$inject('$browser');
5858
expect($location.hashSearch.book).toBeUndefined();
5959
$browser.setUrl(url);

test/servicesSpec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe("service", function(){
1414
$xhrBulk = scope.$inject('$xhr.bulk');
1515
$xhr = scope.$inject('$xhr');
1616
$route = scope.$inject('$route');
17+
scope.$location = inject('$location');
1718
});
1819

1920
afterEach(function(){
@@ -202,6 +203,7 @@ describe("service", function(){
202203

203204
it('should update hash before any processing', function(){
204205
scope = compile('<div>');
206+
scope.$location = scope.$inject('$location');
205207
var log = '';
206208
scope.$watch('$location.hash', function(){
207209
log += this.$location.hashPath + ';';
@@ -291,6 +293,7 @@ describe("service", function(){
291293
this.log = '<init>';
292294
}
293295
scope = compile('<div></div>').$init();
296+
scope.$location = scope.$inject('$location');
294297
$route = scope.$inject('$route');
295298
$route.when('/Book/:book/Chapter/:chapter', {controller: BookChapter, template:'Chapter.html'});
296299
$route.when('/Blank');
@@ -604,6 +607,7 @@ describe("service", function(){
604607
$browser = new MockBrowser();
605608
$browser.cookieHash['preexisting'] = 'oldCookie';
606609
scope = createScope(null, angularService, {$browser: $browser});
610+
scope.$cookies = scope.$inject('$cookies');
607611
});
608612

609613

0 commit comments

Comments
 (0)