aboutsummaryrefslogtreecommitdiffstats
path: root/src/services.js
diff options
context:
space:
mode:
authorMisko Hevery2010-09-22 13:24:40 +0200
committerMisko Hevery2010-09-22 16:17:44 +0200
commit0649009624e8e7bd6fb39537f62c6f00facbfb16 (patch)
treee85077e148220ce75926bffce2d1e7daf8069945 /src/services.js
parenteefb920d0e0345485a8eb120aeecc3b1aa9f6719 (diff)
downloadangular.js-0649009624e8e7bd6fb39537f62c6f00facbfb16.tar.bz2
Refactored the Browser:
- change from using prototype to inner functions to help with better compression - removed watchers (url/cookie) and introduced a poller concept - moved the checking of URL and cookie into services which register with poolers Benefits: - Smaller minified file - can call $browser.poll() from tests to simulate polling - single place where setTimeout needs to be tested - More testable $browser
Diffstat (limited to 'src/services.js')
-rw-r--r--src/services.js23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/services.js b/src/services.js
index a84a55db..a0317f20 100644
--- a/src/services.js
+++ b/src/services.js
@@ -11,14 +11,17 @@ angularService("$location", function(browser){
var scope = this,
location = {parse:parseUrl, toString:toString, update:update},
lastLocation = {};
+ var lastBrowserUrl = browser.getUrl();
- browser.watchUrl(function(url){
- update(url);
- scope.$root.$eval();
+ browser.addPollFn(function(){
+ if (lastBrowserUrl !== browser.getUrl()) {
+ update(lastBrowserUrl = browser.getUrl());
+ scope.$eval();
+ }
});
this.$onEval(PRIORITY_FIRST, update);
this.$onEval(PRIORITY_LAST, update);
- update(browser.getUrl());
+ update(lastBrowserUrl);
return location;
function update(href){
@@ -395,10 +398,14 @@ angularService('$resource', function($xhr){
angularService('$cookies', function($browser) {
- var cookies = {}, rootScope = this;
- $browser.watchCookies(function(newCookies){
- copy(newCookies, cookies);
- rootScope.$eval();
+ var cookies = {}, rootScope = this, lastCookies;
+ $browser.addPollFn(function(){
+ var currentCookies = $browser.cookies();
+ if (lastCookies != currentCookies) {
+ lastCookies = currentCookies;
+ copy(currentCookies, cookies);
+ rootScope.$eval();
+ }
});
this.$onEval(PRIORITY_FIRST, update);
this.$onEval(PRIORITY_LAST, update);