I met interesting situation. All firebase guides and manuals say that we should use .onDisconnect method before all others operations to prevent situation when value has been already set but "onDisconnect" behaviour wasn't described (for example because of sudden internet disconnect).
For example:
userRef.onDisconnect().remove();
userRef.set(value);
But this approach didn't help me in situation when i was rapidly connecting/disconnecting my WIFI. After few disconnections I noticed that some values weren't deleted.
After that I tried to use such code:
userRef.onDisconnect().set(null, function(){
userRef.set(value);
})
Such approach helped me to succesfully solve the problem and prevent saving unnecessary values during unstable internet connection. It is great, but I still don't understand why it works and works better then first variant. All manuals say that it is enough to just put onDisconnect().remove(); before other operations. May be they don't take in consideration situations with extremeley unstable connection, or I have mistaken somewhere? thx
Aucun commentaire:
Enregistrer un commentaire