This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
ng-cookies #10530
Closed
+772
−681
Closed
ng-cookies #10530
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8cf7f34
feat($browser): added options argument support for $browser.cookies()
shahata b080151
refactor($cookieStore): use $browser directly instead of $cookies
shahata b5894ab
feat($cookieStore): add options support for put method
shahata 47550dd
feat($cookieStore): add getRaw/getAll/putAll and deprecate $cookies
shahata 7591568
refactor($browser): split $browser.cookies to $$cookieReader/Writer
shahata 40e4b13
refactor(ngCookies): split $cookies/$cookieStore to two files
shahata c72f935
feat($cookies): add new interface and deprecate $cookieStore
shahata dcdfd08
refactor($browser): removed generic polling mechanism
shahata 5c8ac6c
refactor($cookies): mock $$cookieWriter/$$cookieReader locally
shahata 17f6942
feat($cookies): add options support for remove method
shahata e1c076e
feat($cookies): add provider to set default options
shahata f9281ef
refactor(ngCookies): fixup tests
shahata File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @name $$cookieReader | ||
* @requires $document | ||
* | ||
* @description | ||
* This is a private service for reading cookies used by $http and ngCookies | ||
* | ||
* @return {Object} a key/value map of the current cookies | ||
*/ | ||
function $$CookieReader($document) { | ||
var rawDocument = $document[0]; | ||
var lastCookies = {}; | ||
var lastCookieString = ''; | ||
|
||
function safeDecodeURIComponent(str) { | ||
try { | ||
return decodeURIComponent(str); | ||
} catch (e) { | ||
return str; | ||
} | ||
} | ||
|
||
return function() { | ||
var cookieArray, cookie, i, index, name; | ||
|
||
if (rawDocument.cookie !== lastCookieString) { | ||
lastCookieString = rawDocument.cookie; | ||
cookieArray = lastCookieString.split('; '); | ||
lastCookies = {}; | ||
|
||
for (i = 0; i < cookieArray.length; i++) { | ||
cookie = cookieArray[i]; | ||
index = cookie.indexOf('='); | ||
if (index > 0) { //ignore nameless cookies | ||
name = safeDecodeURIComponent(cookie.substring(0, index)); | ||
// the first value that is seen for a cookie is the most | ||
// specific one. values for the same cookie name that | ||
// follow are for less specific paths. | ||
if (lastCookies[name] === undefined) { | ||
lastCookies[name] = safeDecodeURIComponent(cookie.substring(index + 1)); | ||
} | ||
} | ||
} | ||
} | ||
return lastCookies; | ||
}; | ||
} | ||
|
||
$$CookieReader.$inject = ['$document']; | ||
|
||
function $$CookieReaderProvider() { | ||
this.$get = $$CookieReader; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use strict'; | ||
|
||
angular.module('ngCookies'). | ||
/** | ||
* @ngdoc service | ||
* @name $cookieStore | ||
* @requires $cookies | ||
* | ||
* @description | ||
* Provides a key-value (string-object) storage, that is backed by session cookies. | ||
* Objects put or retrieved from this storage are automatically serialized or | ||
* deserialized by angular's toJson/fromJson. | ||
* | ||
* Requires the {@link ngCookies `ngCookies`} module to be installed. | ||
* | ||
* <div class="alert alert-error"> | ||
* **Note:** The $cookieStore service is deprecated. | ||
* Please use the {@link ngCookies.$cookies `$cookies`} service instead. | ||
* </div> | ||
* | ||
* @example | ||
* | ||
* ```js | ||
* angular.module('cookieStoreExample', ['ngCookies']) | ||
* .controller('ExampleController', ['$cookieStore', function($cookieStore) { | ||
* // Put cookie | ||
* $cookieStore.put('myFavorite','oatmeal'); | ||
* // Get cookie | ||
* var favoriteCookie = $cookieStore.get('myFavorite'); | ||
* // Removing a cookie | ||
* $cookieStore.remove('myFavorite'); | ||
* }]); | ||
* ``` | ||
*/ | ||
factory('$cookieStore', ['$cookies', function($cookies) { | ||
|
||
return { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should write a deprecation message to the console when this service is instantiated? |
||
/** | ||
* @ngdoc method | ||
* @name $cookieStore#get | ||
* | ||
* @description | ||
* Returns the value of given cookie key | ||
* | ||
* @param {string} key Id to use for lookup. | ||
* @returns {Object} Deserialized cookie value. | ||
*/ | ||
get: function(key) { | ||
return $cookies.getObject(key); | ||
}, | ||
|
||
/** | ||
* @ngdoc method | ||
* @name $cookieStore#put | ||
* | ||
* @description | ||
* Sets a value for given cookie key | ||
* | ||
* @param {string} key Id for the `value`. | ||
* @param {Object} value Value to be stored. | ||
*/ | ||
put: function(key, value) { | ||
return $cookies.putObject(key, value); | ||
}, | ||
|
||
/** | ||
* @ngdoc method | ||
* @name $cookieStore#remove | ||
* | ||
* @description | ||
* Remove given cookie | ||
* | ||
* @param {string} key Id of the key-value pair to delete. | ||
*/ | ||
remove: function(key) { | ||
return $cookies.remove(key); | ||
} | ||
}; | ||
|
||
}]); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to add
@deprecated
annotation to this service