Store data in FirefoxOS

I am trying to make some FirefoxOS applications, but I have not seen an easy way to store local data. I heard about IndexedDB, but it seems too complicated. Is there any other alternative? If not, is there an easy tutorial in it?

I decided to store and delete the deleted data (making a request for the croos domain), but I am having some problems with permissions. Do you have an XHR tutorial for FirefoxOS?

Thanks.

+8
firefox-os
source share
4 answers

I recommend you use asyncStorage on top of localStorage, it is an asynchronous version of localStorage with the same api and benefits of IndexedDB.

You can see the code and learn how to use it by reading the comments on the file:

https://github.com/mozilla-b2g/gaia/blob/master/shared/js/async_storage.js

+2
source share

Best IndexDB Index I Can Find, Using IndexDB in MDN.

And there are many Firefox applications for the default OS ( gaia ), such as gallery, browser using IndexDB. You can see how it works in real life.

Or you can use the lighter window.localStorage API, which works like a dictionary.

localStorage.setItem(key, value); localStorage.getItem(key); 

EDIT: Please note that localStorage is not recommended because it blocks the main thread. Instead, use gaia/shared/asyncStorage .

For XHR, you can check out the Firefox-OS-Boilerplate-App for a working XHR demo

+7
source share

The podcast help application talks about indexes and SystemXHR indexes, which is the preferred API for cross-domain requests: https://marketplace.firefox.com/developers/docs/apps/podcasts

+1
source share

You can use the DataStore in firefox Os using the data warehouse, you can also share this data with other applications, and you can also allow other applications to write to the data warehouse or not.

You can follow this link.

https://developer.mozilla.org/en-US/docs/Archive/Firefox_OS/API/Data_Store_API/Using_the_Data_Store_API

Just to use the data warehouse, your application needs to be certified.

 navigator.getDataStores('mystore').then((store)=>{ store[0].getLength().then((ln)=> console.log(ln)) }) 
0
source share

All Articles