refactor(static): split schedule and weather to modules

This commit is contained in:
2026-09-07 18:09:49 +03:00
parent d44c8076b4
commit 5db61da32b
7 changed files with 124 additions and 117 deletions
+41
View File
@@ -0,0 +1,41 @@
export class DataStorage<T extends { id: string }> {
constructor(private storageKey: string) {}
private readValues(): T[] {
const objects = JSON.parse(window.localStorage.getItem(this.storageKey) || "[]");
if (!Array.isArray(objects)) {
return Object.values(objects);
}
return objects;
}
private writeValues(values: T[]) {
window.localStorage.setItem(this.storageKey, JSON.stringify(values));
}
getAll(): T[] {
return this.readValues();
}
add(value: T) {
const values = this.readValues();
for (const v of values) {
if (v.id == value.id) {
return;
}
}
values.push(value);
this.writeValues(values);
}
remove(id: string) {
const values = this.readValues();
for (let i = 0; i < values.length; i++) {
if (values[i].id == id) {
values.splice(i, 1);
this.writeValues(values);
return;
}
}
}
}