Reputation: 73
I have a function that updates a certain property of a document in firebase realtime database. My app reacts to that certain property. My question is if there is no internet connection, will the property in the database be updated? And what is the best way to handle this?
Sample code:
onCancel() {
this.db.object('trips/' tripId).update({
status: 'Canceled'
})
}
Upvotes: 0
Views: 278
Reputation: 7388
It depends on the database you use. And if your are developing for web or native. In native both databases support offline working. In web it's a little bit different:
The Realtime Database supports only the "Tunnel mode" where it will put such requests in a queue
and try them later when reconnectting. That is for exactly such cases where you lose the connection for a short amount of time. You also have tools to listen to connection changes. More about it here.
The Firestore
database supports a full offline working. You would just need to enable it manually:
firebase.firestore().enablePersistence()
.catch((err) => {
if (err.code == 'failed-precondition') {
// Multiple tabs open, persistence can only be enabled
// in one tab at a a time.
// ...
} else if (err.code == 'unimplemented') {
// The current browser does not support all of the
// features required to enable persistence
// ...
}
});
More about it here
Upvotes: 2
Reputation: 1
No the data base won't be updated because for firebase your backend and database is store on the cloud so you'll surely need an Internet connection. In a real life scenario the user using your app will always be connected to the Internet in other fetch data needed for the app to run so there is no need to panic. Just make sure you have a good Internet connection whenever you're coding.
Upvotes: -1