A Jetpack module for using IndexedDB, based on the localForage API
npm install async-storageThis is a module for Mozilla's Addon-SDK that simplifies using IndexedDB in Firefox extensions, based on the localForage library.
The Add-on SDK supports loading modules from a node_modules directory via the jpm tool, so if you're using jpm all you need to do is this:
npm install --save jp-async-storage
If you're using cfx instead ( upgrade! upgrade! ) you can just to this:
cd
wget https://raw.githubusercontent.com/canuckistani/jp-async-storage/master/lib/async-storage.js
let config = {
name: 'my-database',
version: 1
};
AsyncStorage.open(config, function(e, r) {
if (e) throw e;
let item = {_id: 1, string: "Hello world"};
AsyncStorage.setItem('key-'+item._id, item, function() {
if (e) throw e;
// if you got this far, you probably saved data!
});
}):
The localForage api is supported:
* setItem
* getItem
* removeItem
* getItems
* keys
* key
* length
* clear
There are two main differences:
1. Promises are not supported, only callbacks
2. callback arguments are node-style: the first argument is an error, and the second is hopefully your data.
First install jpm with npm install jpm -g, then run jpm test -b nightly -v with Firefox Nightly installed.
* look into using Promises
* consider using a Promise-based initialization method like localForage does with a bit more magic.