StaticApps/src/app/Core/Config.js

45 lines
980 B
JavaScript

(() => {
class Config {
constructor() {
this._config = {};
this.updateCB = {};
}
get data() {
return this._config;
}
get(key, def = null) {
if (this._config[key] !== undefined) {
return this._config[key];
}
this.set(key, def);
return def;
}
getFloat(key, def = 0) {
return parseFloat(this.get(key, def));
}
getInt(key, def) {
return parseInt(this.get(key, def));
}
set(key, value) {
this._config[key] = value;
if (this.updateCB[key]) {
this.updateCB[key](value);
}
}
onUpdate(s, cb) {
this.updateCB[s] = cb;
}
}
moduleLoader.isModuleLoaded(['Registry'], () => {
window.config = new Config();
registry.set('config', window.config);
});
})();