From 3eec8c1a517f8b93a5afd15b7f83b33c5df7e54b Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Sat, 25 Sep 2010 15:29:48 -0700 Subject: Properly initialize cookie service in order to preserve existing cookies - previously the poller initialized the cookie cache too late which was causing previously existing cookies to be deleted by cookie service - refactored the poller api so that the addPollFn returns the added fn - fixed older cookie service tests - removed "this.$onEval(PRIORITY_LAST, update);" because it is not needed --- src/Browser.js | 17 +++++++++++++++-- src/services.js | 7 ++++--- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Browser.js b/src/Browser.js index c7e61e97..e3c768ca 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -79,8 +79,21 @@ function Browser(location, document, head, XHR, $log) { foreach(pollFns, function(pollFn){ pollFn(); }); } self.poll = poll; - self.addPollFn = bind(pollFns, push); - self.startPoller = function(interval, setTimeout){ + + /** + * Adds a function to the list of functions that poller periodically executes + * @return {Function} the added function + */ + self.addPollFn = function(/**Function*/fn){ + pollFns.push(fn); + return fn; + }; + + /** + * Configures the poller to run in the specified intervals, using the specified setTimeout fn and + * kicks it off. + */ + self.startPoller = function(/**number*/interval, /**Function*/setTimeout){ (function check(){ poll(); setTimeout(check, interval); diff --git a/src/services.js b/src/services.js index ddeebe1f..56637573 100644 --- a/src/services.js +++ b/src/services.js @@ -409,16 +409,17 @@ angularService('$cookies', function($browser) { rootScope = this, lastCookies; - $browser.addPollFn(function(){ + //creates a poller fn that copies all cookies from the $browser to service & inits the service + $browser.addPollFn(function() { var currentCookies = $browser.cookies(); if (lastCookies != currentCookies) { lastCookies = currentCookies; copy(currentCookies, cookies); rootScope.$eval(); } - }); + })(); - this.$onEval(PRIORITY_FIRST, update); + //at the end of each eval, push cookies this.$onEval(PRIORITY_LAST, update); return cookies; -- cgit v1.2.3