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
|
|
|
|
2020-07-22 16:43:19 +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;
|
|
|
|
}
|