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

Handle namespace #133

Closed
Shuunen opened this issue Aug 18, 2015 · 10 comments
Closed

Handle namespace #133

Shuunen opened this issue Aug 18, 2015 · 10 comments

Comments

@Shuunen
Copy link

Shuunen commented Aug 18, 2015

Hi,

It would be nice to be able to set a namespace when using store.js, because if you use store on your website and do a store.clear(), it clear all the localStorage and you can probably impact other websites that are using localStorage too.

It could be something like :

store.set('username', 'marcus') // 'username' => 'marcus'
store.get('username') // 'marcus'
store.clear() // clear ALL the localStorage

store.namespace('myNameSpace'); 

store.set('username', 'john') // 'myNameSpace.username' => 'john'
store.get('username') // 'john'
store.clear() // clear all myNameSpace keys in localStorage
@nbubna
Copy link

nbubna commented Aug 18, 2015

Or you could just use store2. It already has namespace support.

@Shuunen
Copy link
Author

Shuunen commented Aug 18, 2015

Nice, I wasn't aware of this one, it should be part of the marcuswestin/store.js readme.

@nbubna : store2 works great, thanks 👍

@nbubna
Copy link

nbubna commented Aug 18, 2015

They're unrelated projects, actually. Marcus and i wrote them separately and with diverging goals. Marcus beat me to the punch with the publication (at least to NPM), so i conceded the name and went with "store2", since mine is more aimed at forward features than backward polyfills. Do take note that you need the store.old.js extension for store2 to work in IE6, if you care.

@Shuunen
Copy link
Author

Shuunen commented Aug 18, 2015

"They're unrelated projects, actually." => Ok so is it still an issue/feature enhancment for this project ?

"you need the store.old.js extension for store2 to work in IE6, if you care" => I don't care about IE < 9 :)

@nbubna
Copy link

nbubna commented Aug 18, 2015

That's up to Marcus, of course.

@marcuswestin
Copy link
Owner

Hi @Shuunen, I'll be pushing a v2 iteration with lots of new features, including the stuff you've mentioned here. It's the result of observing exactly what people want and need on top of basic storage since initial release in 2010.

@nbubna if you're up for a collaborative effort of any sort I'm all ears!

@Download
Copy link

@Shuunen @nbubna I'd like to point out two projects that might be of interest to you guys. First one is my own: memorystorage. It's a simple memory-backed shim for local/sessionStorage. The other is Rhaboo by Adrian May. I actually built MemoryStorage as a fix for Rhaboo not working when Safari is in Private Browsing mode.

Rhaboo's got some pretty smart stuff in it to give you more or less linear performance when the size of objects or arrays you put into localStorage grows. It doesn't just JSON.serialize and JSON.parse the entire 5000 element array every time you change a single field in one of the objects contained in it. By the way I'm totally not saying your code is slow, I wouldn't know, I did not have the time yet to check it :). I'm just saying that Rhaboo might be worth checking out.

Also, my current project leans very heavily on local storage so I'm invested in it. As such I'd be willing to contribute to any mutual effort we might make. Let me know your thoughts.

@marcuswestin
Copy link
Owner

store.js v2 is almost complete, and has namespace functionality (among a bunch of additional addon features - see https://github.com/marcuswestin/store.js/tree/v2-dev/storage & https://github.com/marcuswestin/store.js/tree/v2-dev/addon)

@marcuswestin
Copy link
Owner

Namespaces are now implemented in version 2. Stay tuned for a release in the new year, or get the release candidate at https://github.com/marcuswestin/store.js/tree/v2-dev?files=1

@marcuswestin
Copy link
Owner

marcuswestin commented Feb 28, 2017

Store.js v2.0 has been released with support for namespaces!

var ns1 = store.namespace('ns1')
var ns2 = store.namespace('ns2')
ns1.set('foo', 'bar1')
ns2.set('foo', 'bar2')
ns1.get('foo') == 'bar1'
ns2.get('foo') == 'bar2'

One of the plugins uses it to store expiration timestamps: https://github.com/marcuswestin/store.js/blob/master/plugins/expire.js

If you update to the latest version you will automatically get this functionality plus a bunch more :)

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

4 participants