-
Notifications
You must be signed in to change notification settings - Fork 48
How to verify if local data is synchronized? #69
Comments
Hi @thiagocarvp, you can just use the regular Firebase promise like this: const promise = this.afoDatabase.object('car').update({maxSpeed: 100});
promise.then(() => console.log('data saved to Firebase!')); This promise tells you when your local data is synchronized with Firebase. You might also like reading working with promises. |
Thanks for response! |
@thiagocarvp can you give me an example of what you'd like to do? I think I need a little bit more context. Thanks! |
It would be like to verify if every promise in AngularFire2 Offline is settled, like this: myclass {
counter: number = 0;
update() {
this.counter++;
const promise = this.afoDatabase.object('car').update({maxSpeed: 100});
promise.then(() => {
console.log('data saved to Firebase!');
this.counter--;
});
promise.catch(() => {
this.counter--;
}
}
isSynchronized() {
return this.counter == 0;
}
} But I think this approach will lead to concurrency problems, and in case of app be closed, promises will be lost. |
If I am able to get the promises of emulated updates which are made when app starts, I can count remaining promises, like I said in the comment above. |
Not sure I follow your use case exactly, but you could consider using Promise.all() will only resolve when ALL promises in the array resolves.
|
Thanks @larssn ! |
I'm using AngularFire2 Offline in my Ionic application. I want to verify whether local data is already synchronized with Firebase.
Does it have a function to check that?
The text was updated successfully, but these errors were encountered: