mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-28 19:49:20 +03:00
*.jsx -> *.js
This commit is contained in:
parent
0a2b826f71
commit
e88c193334
98 changed files with 341 additions and 340 deletions
75
dev/Common/ClientStorageDriver/LocalStorage.js
Normal file
75
dev/Common/ClientStorageDriver/LocalStorage.js
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
|
||||
import window from 'window';
|
||||
import {isUnd} from 'Common/Utils';
|
||||
import {isStorageSupported} from 'Storage/RainLoop';
|
||||
import {CLIENT_SIDE_STORAGE_INDEX_NAME} from 'Common/Consts';
|
||||
|
||||
class LocalStorageDriver
|
||||
{
|
||||
constructor() {
|
||||
this.s = window.localStorage || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} key
|
||||
* @param {*} data
|
||||
* @returns {boolean}
|
||||
*/
|
||||
set(key, data) {
|
||||
if (!this.s)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
let storageResult = null;
|
||||
try
|
||||
{
|
||||
const storageValue = this.s.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null;
|
||||
storageResult = null === storageValue ? null : window.JSON.parse(storageValue);
|
||||
}
|
||||
catch (e) {} // eslint-disable-line no-empty
|
||||
|
||||
(storageResult || (storageResult = {}))[key] = data;
|
||||
|
||||
try
|
||||
{
|
||||
this.s.setItem(CLIENT_SIDE_STORAGE_INDEX_NAME, window.JSON.stringify(storageResult));
|
||||
return true;
|
||||
}
|
||||
catch (e) {} // eslint-disable-line no-empty
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} key
|
||||
* @returns {*}
|
||||
*/
|
||||
get(key) {
|
||||
if (!this.s)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
const
|
||||
storageValue = this.s.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null,
|
||||
storageResult = null === storageValue ? null : window.JSON.parse(storageValue);
|
||||
|
||||
return (storageResult && !isUnd(storageResult[key])) ? storageResult[key] : null;
|
||||
}
|
||||
catch (e) {} // eslint-disable-line no-empty
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
static supported() {
|
||||
return isStorageSupported('localStorage');
|
||||
}
|
||||
}
|
||||
|
||||
export {LocalStorageDriver, LocalStorageDriver as default};
|
||||
Loading…
Add table
Add a link
Reference in a new issue