When I start listening for the onDataChange()
event the handler receives a value. This value is the one previously saved locally. Then it immediately calls the handler a second time and retrieves the correct updated value on the cloud.
The documentation says:
You can use the function to read a static snapshot of the contents at a given path, as they existed at the time of the event. This method is triggered once when the listener is attached and again every time the data, including children, changes.
I read "as they existed at the time of the event", not as it existed LOCALLY at the time of the event.
I expect the method to trigger once when is added retrieving the real-time value and not the one saved locally, and then to trigger every time the value is changed.
How to reproduce:
Load an existing object via:
onDataChange(DataSnapshot dataSnapshot)... // value = "Hello world"
Kill the App and change the value via Firebase console to "Hello again World";
Load again the object via:
onDataChange(DataSnapshot dataSnapshot)... // value = "Hello world"
Wait and the handler will be called again immediately after with the value: "Hello again World"
I don't know if this is a bug or if it's by design.
In case this is the default behavior and is by design, is there a way for me to know if the value is the last saved local value?