Skip to content

Commit

Permalink
refactor: add comment to code
Browse files Browse the repository at this point in the history
  • Loading branch information
DAN3002 committed Oct 17, 2023
1 parent b6c8e05 commit 1f1f1c4
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions utils/storage.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
/**
* Sets a value to storage with the given key.
* @param {string} key - The key to set the value.
* @param {*} value - The value to be set.
*/
const setToStorage = (key, value) => {
chrome.storage.sync.set({
[key]: value,
});
// Use chrome.storage.sync to set the key-value pair to storage
chrome.storage.sync.set({ [key]: value });
};

const getFromStorage = (key, defaultValue) => {
return new Promise((resolve) => {
chrome.storage.sync.get([key], (result) => {
resolve(result[key] || defaultValue);
});
});
/**
* Retrieves a value from the Chrome storage sync API using the provided key.
* @param {string} key - The key used to retrieve the value from storage.
* @returns {Promise<any>} - A promise that resolves with the retrieved value.
*/
const getFromStorage = (key) => {
return new Promise((resolve) => {
// Use the chrome.storage.sync.get method to retrieve the value associated with the provided key
chrome.storage.sync.get([key], (result) => {
// Resolve the promise with the retrieved value
resolve(result[key]);
});
});
};

0 comments on commit 1f1f1c4

Please sign in to comment.