(function() {
/**
* @augments Help4.service.StorageService.StorageInterface
* @property {string} _storageName
*/
Help4.service.StorageService.LocalStorage = class extends Help4.service.StorageService.StorageInterface {
/**
* @override
* @constructor
* @param {Help4.jscore.ControlBase.Params} derived
*/
constructor(derived) {
const {TYPES: T} = Help4.jscore.ControlBase;
const {STORAGE_LEVEL: {local}} = Help4.service.StorageService;
super({
params: {
storageLevel: {init: local}
},
statics: {
_storageName: {init: 'localStorage', destroy: false}
},
derived
});
_isAvailable.call(this);
}
/**
* @override
* @param {string} key
* @returns {?string}
*/
get(key) {
return window[this._storageName].getItem(key);
}
/**
* @override
* @param {string} key
* @param {string} value
* @returns {true}
*/
set(key, value) {
return void window[this._storageName].setItem(key, value) || true;
}
/**
* @override
* @param {string} key
* @returns {true}
*/
del(key) {
return void window[this._storageName].removeItem(key) || true;
}
}
/**
* @memberof Help4.service.StorageService.LocalStorage#
* @private
* @returns {boolean}
*/
function _isAvailable() {
let available = false;
try {
// might crash in Chrome due to SecurityError
const s = window[this._storageName];
available = !!(s?.getItem && s?.setItem && s?.removeItem);
} catch(e) {
}
this.dataFunctions.set({available}, {allowReadonlyOverride: true}); // this.available is readonly; allow override
this._isReady = true;
}
})();