adriancarriger / angularfire2-offline

🔌 A simple wrapper for AngularFire2 to read and write to Firebase while offline, even after a complete refresh.
https://angularfire2-offline.firebaseapp.com/
MIT License
207 stars 48 forks source link

Promises filing twice #53

Closed wbhob closed 7 years ago

wbhob commented 7 years ago

When in airplane mode, the app fires the regular promise and the offline promise simultaneously. This is bad because I have no way of checking whether or not they're online, and the promise should fire only once.

FB.push().offline.then and FB.push().then

adriancarriger commented 7 years ago

Hi @wbhob, from what I understand that is currently the expected behavior. Here's what the two promises do:

Why they finish simultaneously

You've noticed that they finish at about the same time. This is because as soon as a write is made Afo will both send the data to Firebase and write the data locally to the device. They often both happen so fast that it appears to happen at the same time.

Example

If you take your app offline, you'll notice that only the offline promise will complete. If you then go back online without a refresh you'll see the regular Firebase promise complete.

Offline presence

Afo doesn't help with managing online/offline presence, but luckly Firebase does

Let me know if I can help out! Thanks 👍

wbhob commented 7 years ago

Right, I understand this, however, the issue is that I need to either persist to the database, or persist it locally. In a real-world use case, there should be a promise that resolves once depending on the current state of the app.

Immediately after writing this, I realized that I was calling push() twice... closing. I will make a PR with some new info regarding promises.

adriancarriger commented 7 years ago

@wbhob thanks for the PR!