Merge pull request #34 from trun/fix/local-storage-disabled

wrap localStorage access in try-catch
release
Etienne Lemay 2017-01-16 09:12:35 -05:00 committed by GitHub
commit 637e456a1f
1 changed files with 9 additions and 2 deletions

View File

@ -12,12 +12,19 @@ function update(state) {
function set(key, value) {
if (!isLocalStorageSupported) return
window.localStorage[`${NAMESPACE}.${key}`] = JSON.stringify(value)
try {
window.localStorage[`${NAMESPACE}.${key}`] = JSON.stringify(value)
} catch (e) {
}
}
function get(key) {
if (!isLocalStorageSupported) return
var value = window.localStorage[`${NAMESPACE}.${key}`]
try {
var value = window.localStorage[`${NAMESPACE}.${key}`]
} catch (e) {
return
}
if (value) {
return JSON.parse(value)