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

Request: add a second argument to get for default value #10

Closed
cdarken opened this issue Apr 18, 2017 · 5 comments
Closed

Request: add a second argument to get for default value #10

cdarken opened this issue Apr 18, 2017 · 5 comments

Comments

@cdarken
Copy link

cdarken commented Apr 18, 2017

It would help to shave a few lines for testing if it's null or not and you have to initialize an array or an object so you can add values to it.

Example:

let storedData = this.$localStorage.get('storedData', {});

instead of

let storedData = this.$localStorage.get('storedData');
if (storedData === null) {
    storedData = {}
}
@cdarken
Copy link
Author

cdarken commented Apr 18, 2017

Ok, I think I missed something. I forgot there is a configuration phase where you define the properties to be stored and I removed manually the key from Chrome developer tools and then it returned null. The default value is initialized when the component is created, if you delete the key while the app is running, you get the error. Same thing happens if you call remove though. I think remove should reset the default value when you remove a key.

@pinguinjkeke
Copy link
Owner

Hi @cdarken. It's a great enhancement! I'll implement it ASAP

@cdarken
Copy link
Author

cdarken commented Apr 18, 2017

Hi, @pinguinjkeke. You mean the reset in case it's removed? Because the default behavior works fine for settings default values at init, now that I remembered how to use it :)

@pinguinjkeke
Copy link
Owner

@cdarken default option writes to localStorage on initialization if it's empty. After remove it will be null.
Adding second argument to get method will give you specified value if null returned from localStorage

@pinguinjkeke
Copy link
Owner

Feature is implemented in 0.2.0 version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants