mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-02 21:12:02 +08:00
Update Client.js
This change made on mobile as test.
This commit is contained in:
parent
88704b5e12
commit
31d9ea53b9
1 changed files with 18 additions and 16 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue