webext-storage 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,8 +8,8 @@ export declare class StorageItem<Base, InferredBase extends (Base | undefined) =
|
|
|
8
8
|
readonly area: chrome.storage.AreaName;
|
|
9
9
|
readonly defaultValue?: InferredBase;
|
|
10
10
|
constructor(key: string, { area, defaultValue, }?: StorageItemOptions<NonNullable<InferredBase>>);
|
|
11
|
-
get()
|
|
12
|
-
set(value: NonNullable<InferredBase>)
|
|
13
|
-
remove()
|
|
11
|
+
get: () => Promise<Return>;
|
|
12
|
+
set: (value: NonNullable<InferredBase>) => Promise<void>;
|
|
13
|
+
remove: () => Promise<void>;
|
|
14
14
|
onChange(callback: (value: NonNullable<InferredBase>) => void, signal?: AbortSignal): void;
|
|
15
15
|
}
|
|
@@ -8,20 +8,20 @@ export class StorageItem {
|
|
|
8
8
|
this.area = area;
|
|
9
9
|
this.defaultValue = defaultValue;
|
|
10
10
|
}
|
|
11
|
-
async
|
|
11
|
+
get = async () => {
|
|
12
12
|
const result = await chromeP.storage[this.area].get(this.key);
|
|
13
13
|
if (!Object.hasOwn(result, this.key)) {
|
|
14
14
|
return this.defaultValue;
|
|
15
15
|
}
|
|
16
16
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return -- Assumes the user never uses the Storage API directly
|
|
17
17
|
return result[this.key];
|
|
18
|
-
}
|
|
19
|
-
async
|
|
18
|
+
};
|
|
19
|
+
set = async (value) => {
|
|
20
20
|
await chromeP.storage[this.area].set({ [this.key]: value });
|
|
21
|
-
}
|
|
22
|
-
async
|
|
21
|
+
};
|
|
22
|
+
remove = async () => {
|
|
23
23
|
await chromeP.storage[this.area].remove(this.key);
|
|
24
|
-
}
|
|
24
|
+
};
|
|
25
25
|
onChange(callback, signal) {
|
|
26
26
|
const changeHandler = (changes, area) => {
|
|
27
27
|
const changedItem = changes[this.key];
|