mirror of
https://github.com/Funkoala14/knowledgebase_law.git
synced 2025-06-09 02:08:16 +08:00
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
|
|
function noop() {}
|
|
|
|
var noopStorage = {
|
|
getItem: noop,
|
|
setItem: noop,
|
|
removeItem: noop
|
|
};
|
|
|
|
function hasStorage(storageType) {
|
|
if ((typeof self === "undefined" ? "undefined" : _typeof(self)) !== 'object' || !(storageType in self)) {
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
var storage = self[storageType];
|
|
var testKey = "redux-persist ".concat(storageType, " test");
|
|
storage.setItem(testKey, 'test');
|
|
storage.getItem(testKey);
|
|
storage.removeItem(testKey);
|
|
} catch (e) {
|
|
if (process.env.NODE_ENV !== 'production') console.warn("redux-persist ".concat(storageType, " test failed, persistence will be disabled."));
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
export default function getStorage(type) {
|
|
var storageType = "".concat(type, "Storage");
|
|
if (hasStorage(storageType)) return self[storageType];else {
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
console.error("redux-persist failed to create sync storage. falling back to noop storage.");
|
|
}
|
|
|
|
return noopStorage;
|
|
}
|
|
} |