draft pref

This commit is contained in:
2024-05-29 12:49:19 +02:00
parent 0a82fca6d3
commit 2d57345634
2 changed files with 22 additions and 0 deletions

View 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
View File