mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-24 10:20:23 +00:00
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.
This commit is contained in:
parent
5f080193cb
commit
d0270d9256
7 changed files with 28 additions and 8 deletions
|
|
@ -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) #
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue