EYHN
2024-03-22 16:43:26 +00:00
parent 05c44db5a9
commit 34703a3b7d
85 changed files with 3248 additions and 2286 deletions
@@ -4,6 +4,17 @@ import { Observable } from 'rxjs';
export class LocalStorageMemento implements Memento {
constructor(private readonly prefix: string) {}
keys(): string[] {
const keys: string[] = [];
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key && key.startsWith(this.prefix)) {
keys.push(key.slice(this.prefix.length));
}
}
return keys;
}
get<T>(key: string): T | null {
const json = localStorage.getItem(this.prefix + key);
return json ? JSON.parse(json) : null;
@@ -29,6 +40,16 @@ export class LocalStorageMemento implements Memento {
channel.postMessage(value);
channel.close();
}
del(key: string): void {
localStorage.removeItem(this.prefix + key);
}
clear(): void {
for (const key of this.keys()) {
this.del(key);
}
}
}
export class LocalStorageGlobalCache