Add settings.deleteItem
This commit is contained in:
parent
a18e462817
commit
696a144ab7
1 changed files with 21 additions and 0 deletions
|
@ -61,3 +61,24 @@ const setItem = (connection, key, value) => {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deleteItem = (connection, key) => {
|
||||||
|
if (!isObject(connection)) {
|
||||||
|
throw new TypeError('"connection" is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isString(key)) {
|
||||||
|
throw new TypeError('"key" must be a string');
|
||||||
|
}
|
||||||
|
|
||||||
|
const transaction = connection.transaction(ITEMS_STORE_NAME, 'readwrite');
|
||||||
|
const itemsStore = transaction.objectStore(ITEMS_STORE_NAME);
|
||||||
|
const request = itemsStore.delete(key);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
request.onerror = event =>
|
||||||
|
reject(event.target.error);
|
||||||
|
|
||||||
|
request.onsuccess = () =>
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue