mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-11-15 20:24:51 +08:00
25 lines
645 B
JavaScript
25 lines
645 B
JavaScript
import { CookieDriver } from 'Common/ClientStorageDriver/Cookie';
|
|
import { LocalStorageDriver } from 'Common/ClientStorageDriver/LocalStorage';
|
|
|
|
const SupportedStorageDriver = [LocalStorageDriver, CookieDriver].find(
|
|
StorageDriver => StorageDriver && StorageDriver.supported()
|
|
);
|
|
|
|
const driver = SupportedStorageDriver ? new SupportedStorageDriver() : null;
|
|
|
|
/**
|
|
* @param {number} key
|
|
* @param {*} data
|
|
* @returns {boolean}
|
|
*/
|
|
export function set(key, data) {
|
|
return driver ? driver.set('p' + key, data) : false;
|
|
}
|
|
|
|
/**
|
|
* @param {number} key
|
|
* @returns {*}
|
|
*/
|
|
export function get(key) {
|
|
return driver ? driver.get('p' + key) : null;
|
|
}
|