snappymail/dev/Storage/Client.jsx

30 lines
671 B
React
Raw Normal View History

2015-11-15 08:23:16 +08:00
import {_} from 'common';
import {CookieDriver} from 'Common/ClientStorageDriver/Cookie';
import {LocalStorageDriver} from 'Common/ClientStorageDriver/LocalStorage';
2015-11-15 08:23:16 +08:00
2016-06-17 07:23:49 +08:00
const SupportedStorageDriver = _.find(
[LocalStorageDriver, CookieDriver], (StorageDriver) => StorageDriver && StorageDriver.supported()
);
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
* @return {boolean}
*/
export function set(key, data)
{
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
* @return {*}
*/
export function get(key)
{
return driver ? driver.get('p' + key) : null;
}