DmitrySharabin / mavo-firebase-firestore

Firebase backend plugin for Mavo. Store and sync app data in milliseconds. Store and serve files at Google scale. Authenticate users simply and securely. All the Google Firebase powers are at your fingertips.
https://plugins.mavo.io/plugin/firebase-firestore
MIT License
6 stars 0 forks source link

Battle between mv-autosave="0" and mv-firebase="realtime" #11

Closed karger closed 4 years ago

karger commented 4 years ago

I wrote an app with mv-autosave="0" and mv-firebase="realtime". If I try to type data into a textfield with a property attribute, mavo goes into an infinite cycle (but doesn't hang) where it saves the data, which causes a data change, which causes the new data to be pushed, which causes a data change, which causes new data to be pushed, etc. In the app my typing replays and saves over and over again, never settling down.

DmitrySharabin commented 4 years ago

For now, this issue is fixed only in the dev version. If you want to give it a try, be my guest. :) Use this URL: https://dmitrysharabin.github.io/mavo-firebase-firestore/src/mavo-firebase-firestore.js But keep in mind that it also uses the new schema: projectId/path/to/collection/filename.

karger commented 4 years ago

I think you may have been waiting for me to comment on this. How did you address the issue? It seems to me the way to break the cycle is to arrange that if the data received from the server via "realtime" is equal to the data that was sent to the server in a previous write, then mavo should ignore what the server sent as out-of-date. I don't know how far back in the write history to check for equality, but since firebase is supposed to be realtime then a few seconds should probably suffice? Actually, if firebase has semantics that guarantee a notification exactly once per write, then we can keep a set of writes that haven't been sent back yet but remove from the set as soon as we get a match. Even better would be if there was a way to configure firebase to say "don't send me a snapshot of the write I just did".

If we ever enable offline mode this gets more complicated.