snappymail/dev/Storage/Client.js

26 lines
645 B
JavaScript
Raw Normal View History

2019-07-05 03:19:24 +08:00
import { CookieDriver } from 'Common/ClientStorageDriver/Cookie';
import { LocalStorageDriver } from 'Common/ClientStorageDriver/LocalStorage';
2015-11-15 08:23:16 +08:00
const SupportedStorageDriver = [LocalStorageDriver, CookieDriver].find(
StorageDriver => StorageDriver && StorageDriver.supported()
2016-06-17 07:23:49 +08:00
);
2015-11-15 08:23:16 +08:00
2016-06-17 07:23:49 +08:00
const driver = SupportedStorageDriver ? new SupportedStorageDriver() : null;
2015-11-15 08:23:16 +08:00
2016-06-17 07:23:49 +08:00
/**
* @param {number} key
* @param {*} data
2016-06-30 08:02:45 +08:00
* @returns {boolean}
2016-06-17 07:23:49 +08:00
*/
2019-07-05 03:19:24 +08:00
export function set(key, data) {
2016-06-17 07:23:49 +08:00
return driver ? driver.set('p' + key, data) : false;
2015-11-15 08:23:16 +08:00
}
2016-06-17 07:23:49 +08:00
/**
* @param {number} key
2016-06-30 08:02:45 +08:00
* @returns {*}
2016-06-17 07:23:49 +08:00
*/
2019-07-05 03:19:24 +08:00
export function get(key) {
2016-06-17 07:23:49 +08:00
return driver ? driver.get('p' + key) : null;
}