mirror of
https://github.com/NovaGM/ModuleBuilder.git
synced 2024-08-15 00:23:33 +00:00
33 lines
594 B
JavaScript
33 lines
594 B
JavaScript
|
export const settingStores = {};
|
||
|
|
||
|
export const makeStore = (key) => {
|
||
|
settingStores[key] = new SimpleStore();
|
||
|
};
|
||
|
|
||
|
class SimpleStore {
|
||
|
constructor() {
|
||
|
this.store = {};
|
||
|
}
|
||
|
|
||
|
getSetting = (key, defaultValue) => {
|
||
|
return this.store[key] ?? defaultValue;
|
||
|
}
|
||
|
|
||
|
updateSetting = (key, value) => {
|
||
|
if (value === undefined) {
|
||
|
return this.toggleSetting(key);
|
||
|
}
|
||
|
|
||
|
this.store[key] = value;
|
||
|
}
|
||
|
|
||
|
toggleSetting = (key) => {
|
||
|
this.store[key] = !this.store[key];
|
||
|
}
|
||
|
|
||
|
deleteSetting = (key) => {
|
||
|
delete this.store[key];
|
||
|
}
|
||
|
|
||
|
getKeys = () => Object.keys(this.store)
|
||
|
}
|