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

Storing a number converts it into a string #99

Closed
skatenerd opened this issue May 22, 2014 · 9 comments
Closed

Storing a number converts it into a string #99

skatenerd opened this issue May 22, 2014 · 9 comments

Comments

@skatenerd
Copy link

localStorageService.add("wat", 99)
//=> true
localStorageService.get("wat")
//=>"99"
@nmehta6
Copy link
Contributor

nmehta6 commented May 22, 2014

local storage doesn't store values by type. It is simply a string key,value pair store.

Trying the following in chrome's console yields the same results.

window.localStorage.setItem('wat', 11)
window.localStorage.getItem('wat')
// => "11"

But I think that it would be a great idea to implement some support for primitive javascript types here.

@skatenerd
Copy link
Author

This is confusing to me, because if you store an object, you get an object back. If you store this, for example: localStorageService.add("an-object", {n: 99})

Then, the inner number (99) doesn't get converted.

I guess I'm struggling to understand when the object will come back unchanged, and when it will come back with some parts turned into a string.

@grevory
Copy link
Owner

grevory commented May 22, 2014

That's true. Someone did a PR to maintain the type of Object. We could add it in for Number as well.

@skatenerd
Copy link
Author

Perhaps we could just serialize/deserialize everything?

@a8m
Copy link
Collaborator

a8m commented Oct 6, 2014

@deweydb
Copy link

deweydb commented Oct 15, 2014

Please excuse my ignorance on how these things work, but does the above committed test spec imply that there are plans to return ints as ints instead of strings?

@a8m
Copy link
Collaborator

a8m commented Oct 16, 2014

@deweydb that's right, If you save a Number, you get a Number, not a String.

@deweydb
Copy link

deweydb commented Oct 16, 2014

Strange, I am still having ints being converted into strings in Chrome. I will produce an example later today and post it.

@a8m
Copy link
Collaborator

a8m commented Oct 16, 2014

@deweydb Which version are you using currently?

@a8m a8m closed this as completed Nov 15, 2014
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

No branches or pull requests

5 participants