mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 21:19:21 +03:00
Code refactoring (v2)
This commit is contained in:
parent
90d95d3ca4
commit
80ab02363e
29 changed files with 858 additions and 857 deletions
|
|
@ -3,30 +3,27 @@ import {_} from 'common';
|
|||
import {CookieDriver} from 'Common/ClientStorageDriver/Cookie';
|
||||
import {LocalStorageDriver} from 'Common/ClientStorageDriver/LocalStorage';
|
||||
|
||||
class ClientStorage
|
||||
const SupportedStorageDriver = _.find(
|
||||
[LocalStorageDriver, CookieDriver], (StorageDriver) => StorageDriver && StorageDriver.supported()
|
||||
);
|
||||
|
||||
const driver = SupportedStorageDriver ? new SupportedStorageDriver() : null;
|
||||
|
||||
/**
|
||||
* @param {number} key
|
||||
* @param {*} data
|
||||
* @return {boolean}
|
||||
*/
|
||||
export function set(key, data)
|
||||
{
|
||||
constructor() {
|
||||
const SupportedStorageDriver = _.find([LocalStorageDriver, CookieDriver],
|
||||
(StorageDriver) => StorageDriver && StorageDriver.supported());
|
||||
this.driver = SupportedStorageDriver ? new SupportedStorageDriver() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} key
|
||||
* @param {*} data
|
||||
* @return {boolean}
|
||||
*/
|
||||
set(key, data) {
|
||||
return this.driver ? this.driver.set('p' + key, data) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} key
|
||||
* @return {*}
|
||||
*/
|
||||
get(key) {
|
||||
return this.driver ? this.driver.get('p' + key) : null;
|
||||
}
|
||||
return driver ? driver.set('p' + key, data) : false;
|
||||
}
|
||||
|
||||
module.exports = new ClientStorage();
|
||||
/**
|
||||
* @param {number} key
|
||||
* @return {*}
|
||||
*/
|
||||
export function get(key)
|
||||
{
|
||||
return driver ? driver.get('p' + key) : null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue