draft pref
This commit is contained in:
22
src/preferences/Preference.ts
Normal file
22
src/preferences/Preference.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
export class Preference<T> {
|
||||
private key: string;
|
||||
private description: string;
|
||||
private value?: T;
|
||||
private defaultValue?: T;
|
||||
|
||||
constructor(key: string, description: string, defaultValue?: T) {
|
||||
this.key = key;
|
||||
this.description = description;
|
||||
this.defaultValue = defaultValue;
|
||||
this.value = this.load();
|
||||
}
|
||||
|
||||
private load() {
|
||||
const value = localStorage.getItem(this.key);
|
||||
|
||||
if (value) {
|
||||
return JSON.parse(value);
|
||||
}
|
||||
return this.defaultValue;
|
||||
}
|
||||
}
|
||||
0
src/preferences/index.ts
Normal file
0
src/preferences/index.ts
Normal file
Reference in New Issue
Block a user