1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 10:43:35 +00:00

html/memory storage services

This commit is contained in:
Kyle Spearrin
2018-06-09 15:26:21 -04:00
parent 561120c51c
commit 9f1c7a0a32
4 changed files with 76 additions and 63 deletions

View File

@@ -0,0 +1,26 @@
import { StorageService } from 'jslib/abstractions/storage.service';
export class MemoryStorageService implements StorageService {
private store = new Map<string, any>();
get<T>(key: string): Promise<T> {
if (this.store.has(key)) {
const obj = this.store.get(key);
return Promise.resolve(obj as T);
}
return Promise.resolve(null);
}
save(key: string, obj: any): Promise<any> {
if (obj == null) {
return this.remove(key);
}
this.store.set(key, obj);
return Promise.resolve();
}
remove(key: string): Promise<any> {
this.store.delete(key);
return Promise.resolve();
}
}