2015-11-15 08:23:16 +08:00
|
|
|
|
|
|
|
import {_} from 'common';
|
2016-01-23 00:51:22 +08:00
|
|
|
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
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {boolean}
|
2016-06-17 07:23:49 +08:00
|
|
|
*/
|
|
|
|
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
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {*}
|
2016-06-17 07:23:49 +08:00
|
|
|
*/
|
|
|
|
export function get(key)
|
|
|
|
{
|
|
|
|
return driver ? driver.get('p' + key) : null;
|
|
|
|
}
|