storage-services eliminados cr Juan
This commit is contained in:
parent
7365a1e001
commit
66c2714233
|
@ -1,7 +1,6 @@
|
|||
import './module-loader';
|
||||
import './crud';
|
||||
import './acl-service';
|
||||
import './storage-services';
|
||||
import './template';
|
||||
import './interpolate';
|
||||
import './copy';
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
import ngModule from '../module';
|
||||
|
||||
class VnStorage {
|
||||
constructor() {
|
||||
this._type = '';
|
||||
this.prefix = 'vn';
|
||||
}
|
||||
set type(value) {
|
||||
this._type = value;
|
||||
this.checkSupport();
|
||||
}
|
||||
get type() {
|
||||
return this._type;
|
||||
}
|
||||
get webStorage() {
|
||||
return window[this.type];
|
||||
}
|
||||
checkSupport() {
|
||||
try {
|
||||
let supported = (this.type in window && window[this.type] !== null);
|
||||
if (supported) {
|
||||
let key = '__' + Math.round(Math.random() * 1e7);
|
||||
let webStorage = window[this.type];
|
||||
webStorage.setItem(key, '');
|
||||
webStorage.removeItem(key);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('VnStorage.notification.error', e.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
get(param) {
|
||||
let toRead = this.webStorage.getItem(`${this.prefix}.${param}`);
|
||||
if (toRead && toRead.startsWith('jsonObject:')) {
|
||||
toRead = JSON.parse(toRead.replace('jsonObject:', ''));
|
||||
}
|
||||
return toRead;
|
||||
}
|
||||
set(param, data) {
|
||||
let toStorage = typeof data === 'object' ? `jsonObject:${JSON.stringify(data)}` : data;
|
||||
this.webStorage.setItem(`${this.prefix}.${param}`, toStorage);
|
||||
}
|
||||
remove(param) {
|
||||
this.webStorage.removeItem(`${this.prefix}.${param}`);
|
||||
}
|
||||
clear() {
|
||||
this.webStorage.clear();
|
||||
}
|
||||
}
|
||||
|
||||
class SessionStorage extends VnStorage {
|
||||
constructor() {
|
||||
super();
|
||||
this.type = 'sessionStorage';
|
||||
}
|
||||
}
|
||||
|
||||
class LocalStorage extends VnStorage {
|
||||
constructor() {
|
||||
super();
|
||||
this.type = 'localStorage';
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.service('sessionStorage', SessionStorage);
|
||||
ngModule.service('localStorage', LocalStorage);
|
Loading…
Reference in New Issue