1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix StorageHelper.get() returning null after clearing

- Return the defaultValue

- Mark default value as required

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-03-31 12:01:26 -04:00
parent da196387b8
commit c6ba0a1f78
2 changed files with 3 additions and 3 deletions

View File

@ -148,7 +148,7 @@ describe("renderer/utils/StorageHelper", () => {
expect(storageHelper.get()).toBeTruthy();
storageHelper.clear();
expect(storageHelper.get()).toBeFalsy();
expect((storageHelper as any).data.get()).toBeFalsy();
expect(storageMock[storageKey]).toBeUndefined();
expect(storageAdapter.removeItem).toHaveBeenCalledWith(storageHelper.key);
});

View File

@ -21,7 +21,7 @@ export interface StorageHelperOptions<T> {
autoInit?: boolean; // start preloading data immediately, default: true
observable?: CreateObservableOptions;
storage: StorageAdapter<T>;
defaultValue?: T;
defaultValue: T;
}
export class StorageHelper<T> {
@ -129,7 +129,7 @@ export class StorageHelper<T> {
}
get(): T {
return this.data.get();
return this.data.get() ?? this.defaultValue;
}
set(value: T) {