mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-25 06:13:44 +00:00
$cookies service should not call $eval during $eval
- added comment - removed $eval call - changed the code to not require $eval - updated specs
This commit is contained in:
parent
c8bb044be1
commit
94737cd017
2 changed files with 17 additions and 18 deletions
|
|
@ -1118,6 +1118,8 @@ angularServiceInject('$cookies', function($browser) {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
//at the end of each eval, push cookies
|
//at the end of each eval, push cookies
|
||||||
|
//TODO: this should happen before the "delayed" watches fire, because if some cookies are not
|
||||||
|
// strings or browser refuses to store some cookies, we update the model in the push fn.
|
||||||
this.$onEval(PRIORITY_LAST, push);
|
this.$onEval(PRIORITY_LAST, push);
|
||||||
|
|
||||||
return cookies;
|
return cookies;
|
||||||
|
|
@ -1128,6 +1130,7 @@ angularServiceInject('$cookies', function($browser) {
|
||||||
*/
|
*/
|
||||||
function push(){
|
function push(){
|
||||||
var name,
|
var name,
|
||||||
|
value,
|
||||||
browserCookies,
|
browserCookies,
|
||||||
updated;
|
updated;
|
||||||
|
|
||||||
|
|
@ -1140,15 +1143,22 @@ angularServiceInject('$cookies', function($browser) {
|
||||||
|
|
||||||
//update all cookies updated in $cookies
|
//update all cookies updated in $cookies
|
||||||
for(name in cookies) {
|
for(name in cookies) {
|
||||||
if (cookies[name] !== lastCookies[name]) {
|
value = cookies[name];
|
||||||
$browser.cookies(name, cookies[name]);
|
if (!isString(value)) {
|
||||||
|
if (isDefined(lastCookies[name])) {
|
||||||
|
cookies[name] = lastCookies[name];
|
||||||
|
} else {
|
||||||
|
delete cookies[name];
|
||||||
|
}
|
||||||
|
} else if (value !== lastCookies[name]) {
|
||||||
|
$browser.cookies(name, value);
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//verify what was actually stored
|
//verify what was actually stored
|
||||||
if (updated){
|
if (updated){
|
||||||
updated = !updated;
|
updated = false;
|
||||||
browserCookies = $browser.cookies();
|
browserCookies = $browser.cookies();
|
||||||
|
|
||||||
for (name in cookies) {
|
for (name in cookies) {
|
||||||
|
|
@ -1161,11 +1171,6 @@ angularServiceInject('$cookies', function($browser) {
|
||||||
}
|
}
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updated) {
|
|
||||||
rootScope.$eval();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -696,23 +696,17 @@ describe("service", function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should ignore non-string values when asked to create a cookie', function() {
|
it('should drop or reset any cookie that was set to a non-string value', function() {
|
||||||
scope.$cookies.nonString = [1, 2, 3];
|
scope.$cookies.nonString = [1, 2, 3];
|
||||||
|
scope.$cookies.nullVal = null;
|
||||||
|
scope.$cookies.undefVal = undefined;
|
||||||
|
scope.$cookies.preexisting = function(){};
|
||||||
scope.$eval();
|
scope.$eval();
|
||||||
expect($browser.cookies()).toEqual({'preexisting': 'oldCookie'});
|
expect($browser.cookies()).toEqual({'preexisting': 'oldCookie'});
|
||||||
expect(scope.$cookies).toEqual({'preexisting': 'oldCookie'});
|
expect(scope.$cookies).toEqual({'preexisting': 'oldCookie'});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should drop any null or undefined properties', function() {
|
|
||||||
scope.$cookies.nullVal = null;
|
|
||||||
scope.$cookies.undefVal = undefined;
|
|
||||||
scope.$eval();
|
|
||||||
|
|
||||||
expect($browser.cookies()).toEqual({'preexisting': 'oldCookie'});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it('should remove a cookie when a $cookies property is deleted', function() {
|
it('should remove a cookie when a $cookies property is deleted', function() {
|
||||||
scope.$cookies.oatmealCookie = 'nom nom';
|
scope.$cookies.oatmealCookie = 'nom nom';
|
||||||
scope.$eval();
|
scope.$eval();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue