Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10 add support for custom storage type - [NEEDS WORK] #11

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

paulcpk
Copy link

@paulcpk paulcpk commented Jul 9, 2018

Closes #10

@coveralls
Copy link

coveralls commented Jul 9, 2018

Coverage Status

Coverage increased (+0.02%) to 85.898% when pulling 4eb4ab8 on fonkgoku:10-add-support-for-custom-storage-type into 0c4bbfd on softvar:master.

@paulcpk
Copy link
Author

paulcpk commented Jul 9, 2018

I actually wrote a test for the additional functionality, should I do something about the decreased test coverage?

@4F2E4A2E
Copy link

@softvar it would be great if you could take a look at this, thank you!

@softvar
Copy link
Owner

softvar commented Jul 11, 2018

@fonkgoku @4F2E4A2E Sure. kinda busy with office work, will check this weekend surely.
Meanwhile, can you please take out some time to write some test cases for the new code and thereby maintaining the code coverage too.
Thanks!

@paulcpk
Copy link
Author

paulcpk commented Jul 12, 2018

@softvar I added some more tests, looking forward to your review :)

src/index.js Outdated
@@ -35,7 +35,7 @@ export default class SecureLS {
constants.EncrytionTypes.BASE64;
this.config.encryptionSecret = config.encryptionSecret;

this.ls = localStorage;
this.ls = config.storageType || localStorage;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong! It should be an object and not a string.
The code should be:

this.config.storageType = config.storageType || 'localStorage';

this.ls = config.storageType || localStorage;
if (config.storageType && config.storageType === 'sessionStorage') {
  this.storage = sessionStorage;
} else {
  this.storage = localStorage;
}

Copy link
Author

@paulcpk paulcpk Jul 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused, you said "It should be an object and not a string", but in your example this.config.storageType is set to a string and not an object 🤔 . Also setting a custom storage type (something like mockStorage) is not possible the way you proposed.

src/index.js Outdated
@@ -35,7 +35,7 @@ export default class SecureLS {
constants.EncrytionTypes.BASE64;
this.config.encryptionSecret = config.encryptionSecret;

this.ls = localStorage;
this.ls = config.storageType || localStorage;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please update this.ls with this.storage since ls denotes localStorage and since you have added the support for sessionStorage as well, we should update the naming. Doing this will break a lot of test cases, so please find and replace all the instances of lib.ls in tests folder and update it with lib.storage.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually thought about doing that at first, but hesitated because of all the test cases. I will go ahead and change it.

@@ -296,4 +296,17 @@ export default class SecureLS {
return this.get(this.utils.metaKey, true);
};

// enable compatiblity with the sessionStorage/localStorage api
getItem(key, isAllKeysData) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods are not required because we need users to use our API so that we can get.set.remove from our own bucket of information. Using method: getAllKeys - will return all the keys so far set. But if we use the methods you added, we won't be able to log those keys. So, please remove them.
Let me know if you need more explanation here.

Copy link
Author

@paulcpk paulcpk Jul 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how these additional methods inhibit getting the information "from our own bucket of information" in any way, they are just references to the original get, set and remove methods. getAllKeys works fine, I locally modified the test in standard.spec.jsL60 to make sure. You can see for yourself if you like 🙂.
Also having these functions is essential for my team's project requirements. This way you can use SecureLS as a drop in solution for sessionStorage/localStorage in all kinds of other frameworks and libraries.
For example, with an apollographql plugin (https://github.com/apollographql/apollo-cache-persist):

import { persistCache } from 'apollo-cache-persist';
import SecureLS from 'secure-ls';

const cache = new InMemoryCache({...});

persistCache({
  cache,
  storage: new SecureLS(),
});
...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also having these functions is essential for my team's project requirements. doesn't mean everyone wants it, right? In that particular case, you should fork the repo, do the changes and use it as per your requirement.
from our own bucket of information means that when this library sets/removes/gets anything, it knows what all was set using it. Consider it like a jar which has all the information.

Copy link
Author

@paulcpk paulcpk Jul 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't mean everyone wants it, right?

True, but I don't see any disadvantage in having them. As outlined in my previous comment, the requirements on which your arguments are grounded in order to dismiss my changes are actually being fulfilled. I don't see how I can convince you any further 😬. If we don't find an agreement here, I will in fact take your advice, just fork the repo and change it to my requirements.

@softvar
Copy link
Owner

softvar commented Jul 14, 2018

I have reviewed the PR and left some comments. Addressing those comments would ensure the library would be working fine with both the types.

Also, since we have examples too, merging this PR without having sessionStorage examples would be incomplete. Please take out some time to add some sessionStorage examples in different files.

Feel free to ask if you have any doubt.

Thanks!

@softvar softvar changed the title 10 add support for custom storage type 10 add support for custom storage type - [NEEDS WORK] Jul 14, 2018
@softvar
Copy link
Owner

softvar commented Jul 25, 2018

Any updates @fonkgoku ? Please let me know if you need any help from my side.

@paulcpk
Copy link
Author

paulcpk commented Jul 31, 2018

Sorry for the late reply, I was still waiting for a reply on this comment #11 (comment)

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.

None yet

4 participants