-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add adapter key prefix #28
Comments
The global configuration tricks look very suspicious to me Maybe something like this? const appPersist = createPersist({
prefix: 'app1/',
// more configuration options can be added in the future, if needed
})
const $isAuthenticated = createStore(false)
appPersist({
store: $isAuthenticated,
key: 'authenticated' // <- actual localStorage key will be "app1/authenticated"
})
// this way we can also persist a value, that is shared for both apps, if we need this
persist({
store: $shared,
key: 'shared-value'
}) |
Hm, I agree, this looks more robust. But it is always irritates me in What about both ways? |
Taking Global configuration: persist.defaults.keyPrefix = 'app/'
const $isAuthenticated = createStore(false)
persist({
store: $isAuthenticated,
key: 'authenticated' // <- actual localStorage key will be "app/authenticated"
}) Instance configuration: const appPersist = persist.create({
keyPrefix: 'app/',
})
const $isAuthenticated = createStore(false)
appPersist({
store: $isAuthenticated,
key: 'authenticated' // <- actual localStorage key will be "app/authenticated"
})
// defaults can be changed on instance as well
appPersist.defaults.keyPrefix = 'app2/' |
I don't know, i really don't like global configration hooks What is correct behavior, if user changed global configuration long after all persists are set? or if global configuration changes on the fly? Maybe forbid to change configuration if there are persisted stores already, or allow to call this |
After several days of thinking I have come to conclusion, that you are right — global configuration will add useless complexity and strange behaviour. Added |
Let's say you have two separate applications on the same domain
As long as they are located on the same domain — they shares same local storage space. And this can lead to keys conflicts. For example, both applications has store
$isAuthenticated
and both applications persists this store with the keyauthenticated
in storage.It could be hard to maintain unique keys manually, so, idea is to add possibility to specify global (per adapter) key prefix. For example:
(This API example is just an idea and subject to change)
The text was updated successfully, but these errors were encountered: