Update Client.js

This change made on mobile as test.
This commit is contained in:
the-djmaze 2020-09-21 22:28:12 +02:00 committed by GitHub
parent 88704b5e12
commit 31d9ea53b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,14 @@
import { CLIENT_SIDE_STORAGE_INDEX_NAME } from 'Common/Consts';
const storage = localStorage;
const storage = localStorage,
getStorage = () => {
try {
const value = storage.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null;
return null == value ? null : JSON.parse(value);
} catch (e) {
return null;
}
};
/**
* @param {number} key
@ -8,20 +16,15 @@ const storage = localStorage;
* @returns {boolean}
*/
export function set(key, data) {
let storageResult = null;
try {
const storageValue = storage.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null;
storageResult = null === storageValue ? null : JSON.parse(storageValue);
} catch (e) {} // eslint-disable-line no-empty
(storageResult || (storageResult = {}))['p' + key] = data;
const storageResult = getStorage() || {};
storageResult['p' + key] = data;
try {
storage.setItem(CLIENT_SIDE_STORAGE_INDEX_NAME, JSON.stringify(storageResult));
return true;
} catch (e) {} // eslint-disable-line no-empty
return false;
} catch (e) {
return false;
}
}
/**
@ -31,11 +34,10 @@ export function set(key, data) {
export function get(key) {
try {
key = 'p' + key;
const storageValue = storage.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null,
storageResult = null === storageValue ? null : JSON.parse(storageValue);
const storageResult = getStorage();
return storageResult && null != storageResult[key] ? storageResult[key] : null;
} catch (e) {} // eslint-disable-line no-empty
return null;
} catch (e) {
return null;
}
}