Store data in FirefoxOS
Asked Answered
K

4

8

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.

Kokoruda answered 23/4, 2013 at 15:13 Comment(1)
IndexedDB is not that hard. The hardest part (for me at least) has been to architect my apps around DB events.Vita
O
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

Outcross answered 20/5, 2013 at 18:9 Comment(0)
M
7

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

Mathis answered 23/4, 2013 at 22:2 Comment(1)
I just want to highlight one of the sentences in the above comment: use gaia/shared/asyncStorage, it is a simple API that has both the advantages of localStorage (it's simple) and those of indexedDB (it's high performance).Opposition
O
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

Outcross answered 20/5, 2013 at 18:9 Comment(0)
S
1

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

Stereotype answered 24/4, 2013 at 14:41 Comment(0)
T
0

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))
})
Tanguay answered 3/8, 2017 at 11:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.