audio-vis/raw/javascript/config.js

38 lines
787 B
JavaScript
Raw Normal View History

2020-08-01 21:51:54 +02:00
class Config {
constructor() {
this.config = {};
this.name = ''
}
loadConfigByName(name) {
this.save();
2020-08-01 21:51:54 +02:00
this.name = 'config-' + name;
let item = localStorage.getItem(this.name);
if (item) {
this.config = JSON.parse(item);
}
2020-08-01 21:51:54 +02:00
}
save() {
2020-08-01 21:51:54 +02:00
if (this.name !== '') {
localStorage.setItem(this.name, JSON.stringify(this.config));
}
}
set(name, value) {
2020-08-01 21:51:54 +02:00
this.config[name] = value;
}
remove(name) {
2020-08-01 21:51:54 +02:00
delete this.config[name];
}
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;
}
}