Skip to content

Instantly share code, notes, and snippets.

@smolinari
Created April 29, 2020 11:34
Show Gist options
  • Save smolinari/65a2d9e7f4ac377b58bb232742ea7881 to your computer and use it in GitHub Desktop.
Save smolinari/65a2d9e7f4ac377b58bb232742ea7881 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