Skip to content

Instantly share code, notes, and snippets.

@MuhammadKhizar7
Forked from smolinari/db.js
Created November 1, 2021 11:00
Show Gist options
  • Save MuhammadKhizar7/a97ab6a4b1e332a6c40009e075327953 to your computer and use it in GitHub Desktop.
Save MuhammadKhizar7/a97ab6a4b1e332a6c40009e075327953 to your computer and use it in GitHub Desktop.
The services/db.js file for the Quasar todo browser extension demo
export default {
/**
* This will ask for ALL items from chrome storage and return only the ones we're interested in.
* @param type
*/
getAll (type) {
return this.get(null).then(allItems => {
return allItems.filter(f => f && f.type && f.type === type)
})
},
/**
* Use the bridge to contact the background BEX script and get a given key from BEX storage.
* @param key
* @param id
* @returns {Promise<unknown>}
*/
get (key, id = null) {
const useKey = id
? `${key}.${id}`
: key
return window.QBexBridge.send('storage.get', {
key: useKey
}).then(event => {
return event.data
})
},
/**
* Use the bridge to contact the background BEX script and save a given key to the BEX storage.
* @param key
* @param data
* @returns {Promise<unknown>}
*/
save (key, data) {
return window.QBexBridge.send('storage.set', { key, data }).then(event => {
return event.data
})
},
/**
* Use the bridge to contact the background BEX script and delete a given key from BEX storage.
* @param key
* @param id
* @returns {Promise<unknown>}
*/
delete (key, id) {
return window.QBexBridge.send('storage.remove', {
key: `${key}.${id}`
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment