Add localStorage & sessionStorage factories - #42
Closed
efolio wants to merge 1 commit into
Closed
Conversation
Collaborator
Author
|
About the failing test, I couldn't try it here on my machine so I assumed it was ok. I'll let you correct the tests if necessary if you approve this PR. |
Collaborator
|
I think this PR is outdated-let's close this to keep things tidy. If you still want this merged, please let me know @efolio. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I needed to do the same as angularLocalStorage but using sessionStorage.
I thought that instead of creating a new library, I could patch this one to provide the same possibilities but using sessionStorage :)
SessionStorage is the same as localStorage, an object inheriting Storage (see https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage), but with limited persistence (as long as the tab remains opened in the browser).
This PR provides 3 factories instead of one:
The storage service now needs as first argument of each of its methods the storage provider to use ($window.localStorage for example). localStorage and sessionStorage providers are shortcuts that provide the right parameter.
The localStorage service uses $window.localStorage and $cookieStore as a fallback as before.
The sessionStorage service uses only the $window.sessionStorage if available.
I am aware that this PR would break the current API (meaning you would have to inject "localStorage" instead of "storage").
However, I believe that this would be the right way to go in order to handle any kind of storage provider easily and elegantly.