-
Notifications
You must be signed in to change notification settings - Fork 89
Support for sessionStorage? #19
Comments
Hey there, Why would you use sessionStorage instead of cookies as the fallback? Cookies are available everywhere! I'm open to being able to set which store to use and implementing Makes sense? Cheers! |
We want to store some application lifecycle data like paging and sorting options or form data. We use the session store because it's user specific and is persistent as long the user has a valid session. If we would use local storage, we have to manage which data is from what user since the data is persisted longer. So that would mean more management overhead. So the idea was that this module can also take care of the session storage. Salute |
Makes complete sense. My thoughts are the following: Let's make $cookies, localStorage and sessionStorage different services objects. Then, when you create a namespaced storage, you just pass the store back you want to use which is just the service name that'll be injected using angular.module('app', ['angular-storage'])
.factory('Auth0Store', function(store) {
return store.getNamespacedStore('auth0', 'sessionStorage');
}) What do you think about this aproach? |
Are you willing to PR something like that? |
Yeah, that sounds great. And the fallback pipeline would be local storage -> session storage -> cookie storage in case no store is passed by the user? I could try to implement this. |
sounds good :). If you want, once you start doing commits or have the interface just shoot me a message and I can check the code :). Thanks! |
I will start tomorrow. Btw, nice to see that you are using our karma-mocha-reporter. Makes me happy 😃 |
hahaha it works really nice :) I really like it! |
I guess i am ready. You can have a look at the changes in my fork (https://github.com/4kochi/angular-storage). I added a method I also fixed some minor problems with tests and bower/package.json. I hope you are happy with the changes... |
Hey, Thanks for the update. It looks good. I only have one comment. I'd make the Internal store constructor and the getNamspacedStore methods actually receive as a parameter That way, you can configure the storage when creating the store and not only afterwards. Makes sense? I'll update the README accordingly once the PR gets merged. Thanks! |
Well, that would be a breaking change. And how to pass the param to the InternalStorage constructor? Because as user you inject the store service and receive an instance of the InternalStorage service. So no chance to pass a storageName. Or did I miss something? |
Yes, that'd be a breaking change but I think it's worth it. You can just pass the name and then use Makes sense? |
Ok, but i am still struggling how the user can pass the angular.module('app', ['angular-storage'])
.controller('Controller', function(store) {
var myObj = {
name: 'mgonto'
};
// store is already initialized, how to pass storageName?
store.set('obj', myObj);
}); |
So what I'd do is 2 things. First, for creating a new namespaced storage. .factory('Auth0Store', function(store) {
return store.getNamespacedStore('auth0', 'sessionStorage');
}) For changing the basic one, I'd convert the store into a function config(storeProvider) {
storeProvider.setStore('localStorage');
} What do you think :)? Sorry I wasn't clear before! |
Ok, that i was thinking about. But i tried to avoid it because it's a breaking change. But since this is no problem for you, i will convert the InternalStorage to a provider. Maybe it makes sense that the function
|
Changed store to a provider. Have a look. |
Looks great :). If tests pass just shoot the PR :). Have you added tests for sessionStorage? Thanks! |
Yes, i have. Will merge this evening. I can also add a code coverage report for the test so one can find all the code which is not covered by the tests. |
Awesome thanks for all the help @4kochi |
Your welcome 👍 |
Hi auth0 team,
great work so far. Are there any plans to also support sessionStorage as a store. Ideally the user can configure which store to use, but the fallback is always the sessionStorage. I am open to add a pull request with the feature.
Greetings
The text was updated successfully, but these errors were encountered: