Skip to content

Add localStorage & sessionStorage factories - #42

Closed
efolio wants to merge 1 commit into
agrublev:masterfrom
efolio:master
Closed

Add localStorage & sessionStorage factories#42
efolio wants to merge 1 commit into
agrublev:masterfrom
efolio:master

Conversation

@efolio

@efolio efolio commented Feb 12, 2014

Copy link
Copy Markdown
Collaborator

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:

  • storage
  • localStorage
  • sessionStorage

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.

@efolio

efolio commented Feb 12, 2014

Copy link
Copy Markdown
Collaborator Author

About the failing test, I couldn't try it here on my machine so I assumed it was ok.
However, the test fails because PhantomJS has no sessionStorage, that's all.

I'll let you correct the tests if necessary if you approve this PR.

@capaj

capaj commented Aug 3, 2019

Copy link
Copy Markdown
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.

@capaj capaj closed this Aug 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants