2020-08-01 21:51:54 +02:00
|
|
|
class Config {
|
|
|
|
constructor() {
|
|
|
|
this.config = {};
|
|
|
|
this.name = ''
|
|
|
|
}
|
|
|
|
|
|
|
|
loadConfigByName(name) {
|
2020-08-05 11:24:59 +02:00
|
|
|
this.save();
|
2020-08-01 21:51:54 +02:00
|
|
|
this.name = 'config-' + name;
|
2020-08-05 11:24:59 +02:00
|
|
|
let item = localStorage.getItem(this.name);
|
|
|
|
if (item) {
|
|
|
|
this.config = JSON.parse(item);
|
|
|
|
}
|
2020-08-01 21:51:54 +02:00
|
|
|
}
|
|
|
|
|
2020-08-05 11:24:59 +02:00
|
|
|
save() {
|
2020-08-01 21:51:54 +02:00
|
|
|
if (this.name !== '') {
|
|
|
|
localStorage.setItem(this.name, JSON.stringify(this.config));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-05 11:24:59 +02:00
|
|
|
set(name, value) {
|
2020-08-01 21:51:54 +02:00
|
|
|
this.config[name] = value;
|
|
|
|
}
|
|
|
|
|
2020-08-05 11:24:59 +02:00
|
|
|
remove(name) {
|
2020-08-01 21:51:54 +02:00
|
|
|
delete this.config[name];
|
|
|
|
}
|
|
|
|
|
2020-08-05 11:24:59 +02:00
|
|
|
get(name, def) {
|
2020-08-01 21:51:54 +02:00
|
|
|
let value = this.config[name];
|
|
|
|
if (value === undefined || value === null) {
|
|
|
|
this.config[name] = def;
|
|
|
|
value = def;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|