Question

I'm trying to do some FirefoxOS apps, but I have not seen any easy way to store local data. I hear about IndexedDB, but it seems too complex. Is there any other alternative? If not, is there any easy tutorial about it?

I have considered to store and recove remote data (doing a croos domain request), but I'm having some issues with the permissions. Is there any tutorial about XHR for FirefoxOS?

Thanks.

Was it helpful?

Solution 2

I recommend you using asyncStorage over localStorage, is an asynchronous version of localStorage, with the same api and the benefits of IndexedDB.

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

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

OTHER TIPS

The best IndexDB doc I can found is Using IndexDB in MDN.

And there are plenty of default Firefox OS apps (gaia) such as gallery, browser using IndexDB. You can see how it works in real life.

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

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

EDIT: Note that localStorage is not recommend because its block the main thread. You should use gaia/shared/asyncStorage instead.

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

The podcasts reference app talks about both IndexedDB and SystemXHR, which is the privileged API for doing cross-domain requests: https://marketplace.firefox.com/developers/docs/apps/podcasts

You can use DataStore in firefox Os by using data store you can also share that data with other apps and you can also give permission to other apps to write in data store 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 for using data store your app need to certified.

navigator.getDataStores('mystore').then((store)=>{
    store[0].getLength().then((ln)=> console.log(ln))
})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top