[moblie] use prefix for localStorage items

This commit is contained in:
Maxim Kadushkin 2022-07-13 16:58:53 +03:00
parent 9093eab85f
commit 7e9ccd694a

View file

@ -8,6 +8,7 @@ class LocalStorage {
}); });
this._store = {}; this._store = {};
this._prefix = 'mobile-';
try { try {
this._isAllowed = !!window.localStorage; this._isAllowed = !!window.localStorage;
@ -32,6 +33,14 @@ class LocalStorage {
return this._filter; return this._filter;
} }
get prefix() {
return this._prefix;
}
set prefix(p) {
this._prefix = p;
}
sync() { sync() {
if ( !this._isAllowed ) if ( !this._isAllowed )
Common.Gateway.internalMessage('localstorage', {cmd:'get', keys:this._filter}); Common.Gateway.internalMessage('localstorage', {cmd:'get', keys:this._filter});
@ -43,6 +52,7 @@ class LocalStorage {
} }
setItem(name, value, just) { setItem(name, value, just) {
name = this._prefix + name;
if ( this._isAllowed ) { if ( this._isAllowed ) {
try { try {
localStorage.setItem(name, value); localStorage.setItem(name, value);
@ -57,6 +67,7 @@ class LocalStorage {
} }
getItem(name) { getItem(name) {
name = this._prefix + name;
if ( this._isAllowed ) if ( this._isAllowed )
return localStorage.getItem(name); return localStorage.getItem(name);
else return this._store[name]===undefined ? null : this._store[name]; else return this._store[name]===undefined ? null : this._store[name];