When setting up a listener for the realtime database :
firebaseDb.ref(ref).on('value', (snapshot) => {
console.log('snap', snap);
const response = snapshot.val();
});
The snapshot is saved for offline use, and upon page refresh, the console will display the cached snapshot followed by the server snapshot.
In my complex application, I have nested data binding:
const userBind = (userRef: string) => firebaseDb.ref(userRef).on('value', (snapshot) => {
console.log('snap', snap);
const user = snapshot.val();
store.commit(SET_USER, user);
getUserFriends(user);
});
const getUserFriends = async (user: User) => {
const userFriends = await getUserFriendsData();
store.commit(SET_USER_FRIENDS, userFriends);
};
However, store.commit(SET_USER, user);
and getUserFriendsData()
are being called twice, causing performance issues. Disabling the caching of the realtime database seems like the best solution in this scenario.
Having a feature similar to Android SDK's
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
would be beneficial.
What are your thoughts?
Regards, Florian.