forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.ts
More file actions
34 lines (28 loc) · 944 Bytes
/
settings.ts
File metadata and controls
34 lines (28 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { injecStorage } from '../storage/inject-storage';
import { StorageParams, getDefaultValue } from '../storage/storage-params';
export class Settings {
private static instance: Settings;
private _settings = new Map();
constructor() {
if (Settings.instance) {
throw new Error('Error - use Settings.getInstance()');
}
}
static getInstance(): Settings {
Settings.instance = Settings.instance || new Settings();
return Settings.instance;
}
async getSetting(param: StorageParams) {
if (this._settings.has(param)) return this._settings.get(param);
else return await this.getValue(param);
}
async reloadSetting(param: StorageParams) {
await this.getValue(param);
}
private async getValue(param: StorageParams) {
const storage = injecStorage();
const value = await storage.getValue(param, getDefaultValue(param));
this._settings.set(param, value);
return value;
}
}