You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

44 lines
1.4 KiB

"use strict";
exports.__esModule = true;
exports.default = getStorage;
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;
}
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;
}
}