Added docs idb proxy.
Some checks are pending
Check SPDX-License-Identifier / check-spdx-license-id (push) Waiting to run
Check copyright year / check_copyright_year (push) Waiting to run
Publish Docker image (develop) / Build (linux/amd64) (push) Waiting to run
Publish Docker image (develop) / Build (linux/arm64) (push) Waiting to run
Publish Docker image (develop) / merge (push) Blocked by required conditions
Dockle / dockle (push) Waiting to run
Storybook / build (push) Waiting to run
Test (production install and build) / production (20.16.0) (push) Waiting to run
Some checks are pending
Check SPDX-License-Identifier / check-spdx-license-id (push) Waiting to run
Check copyright year / check_copyright_year (push) Waiting to run
Publish Docker image (develop) / Build (linux/amd64) (push) Waiting to run
Publish Docker image (develop) / Build (linux/arm64) (push) Waiting to run
Publish Docker image (develop) / merge (push) Blocked by required conditions
Dockle / dockle (push) Waiting to run
Storybook / build (push) Waiting to run
Test (production install and build) / production (20.16.0) (push) Waiting to run
This commit is contained in:
parent
7f6b486976
commit
2e51e779e7
|
@ -26,6 +26,7 @@ if (window.Cypress) {
|
|||
console.log('Cypress detected. It will use localStorage.');
|
||||
}
|
||||
|
||||
// Check for the availability of indexedDB.
|
||||
if (idbAvailable) {
|
||||
await iset('idb-test', 'test')
|
||||
.catch(err => {
|
||||
|
@ -37,16 +38,36 @@ if (idbAvailable) {
|
|||
console.error('indexedDB is unavailable. It will use localStorage.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value from indexedDB (or localStorage as a fallback).
|
||||
*
|
||||
* @param key The key of the item to retrieve.
|
||||
*
|
||||
* @returns The value of the item.
|
||||
*/
|
||||
export async function get(key: string) {
|
||||
if (idbAvailable) return iget(key);
|
||||
return miLocalStorage.getItemAsJson(`${PREFIX}${key}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a value in indexedDB (or localStorage as a fallback).
|
||||
*
|
||||
* @param {string} key - The key of the item to set.
|
||||
* @param {any} val - The value of the item to set.
|
||||
* @returns {Promise<void>} - A promise that resolves when the value has been set.`
|
||||
*/
|
||||
export async function set(key: string, val: any) {
|
||||
if (idbAvailable) return iset(key, val);
|
||||
return miLocalStorage.setItemAsJson(`${PREFIX}${key}`, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a value from indexedDB (or localStorage as a fallback).
|
||||
*
|
||||
* @param {string} key - The key of the item to delete.
|
||||
* @returns {Promise<void>} - A promise that resolves when the value has been deleted.
|
||||
*/
|
||||
export async function del(key: string) {
|
||||
if (idbAvailable) return idel(key);
|
||||
return miLocalStorage.removeItem(`${PREFIX}${key}`);
|
||||
|
|
Loading…
Reference in a new issue