Closed wbhob closed 7 years ago
Hi @wbhob, from what I understand that is currently the expected behavior. Here's what the two promises do:
promise
will complete after the write has been made to Firebasepromise.offline
will complete after a write to the local device has been made. This let's you know that if you refresh/close your app at this point that the data is stored on the device. When the device gains access to the internet again, it will try to write the data to Firebase.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.
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.
Afo doesn't help with managing online/offline presence, but luckly Firebase does
Let me know if I can help out! Thanks 👍
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.
@wbhob thanks for the PR!
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