Last active
August 3, 2016 19:09
-
-
Save jschr/e69ee94f66811b17bb7bb3717a89a6e6 to your computer and use it in GitHub Desktop.
chrome local storage module for redux-persist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
getItem(key, cb) { | |
chrome.storage.local.get(null, (data) => { | |
if (chrome.runtime.lastError) return cb(chrome.runtime.lastError) | |
// data will be null if local storage is empty | |
data = data || {} | |
cb(null, data[key]) | |
}) | |
}, | |
setItem(key, value, cb) { | |
chrome.storage.local.set({ [key]: value }, () => { | |
if (chrome.runtime.lastError) return cb(chrome.runtime.lastError) | |
cb(null) | |
}) | |
}, | |
removeItem(key, cb) { | |
chrome.storage.local.remove(key, () => { | |
if (chrome.runtime.lastError) return cb(chrome.runtime.lastError) | |
cb(null) | |
}) | |
}, | |
getAllKeys(cb) { | |
chrome.storage.local.get(null, (data) => { | |
if (chrome.runtime.lastError) return cb(chrome.runtime.lastError) | |
data = data || {} | |
cb(null, Object.keys(data)) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment