marcuswestin / store.js

Cross-browser storage for all use cases, used across the web.
MIT License
14.01k stars 1.33k forks source link

How to use store.createStore(storages, plugins, namespace) ? #237

Closed NicksonYap closed 7 years ago

NicksonYap commented 7 years ago

Hi,

2 weeks ago I used the store.namespace() function and there wasn't an error.

After updating the the latest store.js, a warning appears in console: store.namespace is deprecated. Use store.createStore(storages, plugins, namespace)

I used webpack to combine my packages, and I used: window.store = require('store');

From the README file, I understand storages and plugins are an array of the required js files, but the thing is, should we be declaring the namespace at client-side (the browser)?

Thanks!

marcuswestin commented 7 years ago

I deprecated store.namespace() in favor of store.createStore because I thought it would end up adding too much confusion and complexity around plugins with state (since the plugins are inherited by the namespaced store, but the plugins' state is not (e.g store.defaults({ foo:'bar' }); store.namespace('cat').get('foo') != bar). I didn't take into account that most users use one of the pre-built distributions, which means they're unfamiliar with createStore(). I've undeprecated store.namespace("foo"), and will simply make it clear in the docs that it is an alias for store.createStore(store.storage, store.plugins, "foo") and what to expect from plugins.

This will be part of v2.0.10 release later today.