snappymail/dev/Storage/Client.jsx
2016-06-17 02:32:16 +03:00

29 lines
671 B
JavaScript

import {_} from 'common';
import {CookieDriver} from 'Common/ClientStorageDriver/Cookie';
import {LocalStorageDriver} from 'Common/ClientStorageDriver/LocalStorage';
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)
{
return driver ? driver.set('p' + key, data) : false;
}
/**
* @param {number} key
* @return {*}
*/
export function get(key)
{
return driver ? driver.get('p' + key) : null;
}