-
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
Disabled localStorage will immediately throw error #25
Comments
Actually, I'm not sure what correct behaviour should be in that case:
Any item, except 1 — is breaking change, because some code may already depends on runtime error throwing. |
Maybe extend adapters with optional function import { persist, supports } from 'effector-storage/local'
const reason = supports()
if (reason != null) {
console.log('localStorage is not supported:', reason)
} And |
Is this will work in that way? function isLSDefined() {
try {
return typeof localStorage !== 'undefined'
} catch (err) {
return false
}
}
Usually you might imagine code which rely on any throwable case and you'll unable to add even new properties try {
persist().anyProperty.toString()
} catch {
// business logic goes here
return 'ok'
}
return 'damn effector-storage 😠' |
Yes, it is possible to catch this error, and go by 2 way — behave like there is no I thought about smth like this, maybe: function supports() {
try {
if (typeof localStorage === 'undefined') {
return new Error('localStorage is undefined')
}
} catch (error) {
return error
}
} Function, which could get the reason, without throwing error. |
Fixed in version 4.4.0 |
This line will immediately fail if
localStorage
is disabledeffector-storage/src/local/index.ts
Line 45 in 3587df8
In Chrome:
In Safari on iOS:
Same applies to
sessionStorage
as well.The text was updated successfully, but these errors were encountered: