mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 05:13:29 +00:00
Ps/pm 2910/state framework improvements (#6860)
* Allow for update logic in state update callbacks * Prefer reading updates to sending in stream * Inform state providers when they must deserialize * Update DefaultGlobalState to act more like DefaultUserState * Fully Implement AbstractStorageService * Add KeyDefinitionOptions * Address PR feedback * More Descriptive Error --------- Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import { StorageOptions } from "../src/platform/models/domain/storage-options";
|
||||
export class FakeStorageService implements AbstractStorageService {
|
||||
private store: Record<string, unknown>;
|
||||
private updatesSubject = new Subject<StorageUpdate>();
|
||||
private _valuesRequireDeserialization = false;
|
||||
|
||||
/**
|
||||
* Returns a mock of a {@see AbstractStorageService} for asserting the expected
|
||||
@@ -32,6 +33,14 @@ export class FakeStorageService implements AbstractStorageService {
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
internalUpdateValuesRequireDeserialization(value: boolean) {
|
||||
this._valuesRequireDeserialization = value;
|
||||
}
|
||||
|
||||
get valuesRequireDeserialization(): boolean {
|
||||
return this._valuesRequireDeserialization;
|
||||
}
|
||||
|
||||
get updates$() {
|
||||
return this.updatesSubject.asObservable();
|
||||
}
|
||||
@@ -48,13 +57,13 @@ export class FakeStorageService implements AbstractStorageService {
|
||||
save<T>(key: string, obj: T, options?: StorageOptions): Promise<void> {
|
||||
this.mock.save(key, options);
|
||||
this.store[key] = obj;
|
||||
this.updatesSubject.next({ key: key, value: obj, updateType: "save" });
|
||||
this.updatesSubject.next({ key: key, updateType: "save" });
|
||||
return Promise.resolve();
|
||||
}
|
||||
remove(key: string, options?: StorageOptions): Promise<void> {
|
||||
this.mock.remove(key, options);
|
||||
delete this.store[key];
|
||||
this.updatesSubject.next({ key: key, value: undefined, updateType: "remove" });
|
||||
this.updatesSubject.next({ key: key, updateType: "remove" });
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user