extension-api-compilation
Version:
Cross browser extension api
42 lines (39 loc) • 1.34 kB
JavaScript
import SyncStorage from './sync-storage';
export default class ChromeSyncStorage extends SyncStorage{
/**
* Set data to chrome sync storage
* @param data {Object} An object which gives each key/value pair to update storage with
* @returns {Promise} Promise will be called with created data or failure
*/
set(data) {
return new Promise(function (resolve, reject) {
chrome.storage.sync.set(data, function(response) {
if (response instanceof Error) {
reject(chrome.runtime.lastError);
}
resolve(response);
});
});
}
/**
* Get data from chrome sync storage
* @param key {string|Array} A single key or list of keys to get the total usage for. An empty list will return 0. Pass in null to get the total usage of all of storage.
* @returns {Promise} The promise will associated data on success or error otherwise
*/
get(key) {
return new Promise(function (resolve, reject) {
chrome.storage.sync.get(key, function(response) {
if (response instanceof Error) {
reject(chrome.runtime.lastError);
}
resolve(response);
});
});
}
/**
* Clear all data associated with current extension from sync storage
*/
clear() {
chrome.storage.sync.clear();
}
}