szaranger / firebase-saga

A library for connecting redux-saga middleware to Firebase.
58 stars 15 forks source link

Sync Child_added & Child_removed with depth causes issue in reducer #22

Open hunterwilliams opened 7 years ago

hunterwilliams commented 7 years ago
yield fork(sync, path, {
    [CHILD_ADDED]: actions.syncNotificationAdded,
    [CHILD_REMOVED]: actions.syncNotificationDeleted,
  }, 1);

If I delete a notification or try to add one it calls both seemingly in a random order which causes problems. If I remove the depth specifier it works 100% as expected.

hunterwilliams commented 6 years ago

Okay so a year later I've finally found the real issue and a solution. This is caused by firebase itself and how limit (1). Unfortunately the library abstracts away that layer.

If you want to do child_added 1 pretty much don't. Just do child_added w/o a depth. However this can cause large data pulls. Do a getAll immediately after sync. This uses a firebase caching mechanism found here: https://firebase.google.com/docs/database/admin/retrieve-data#section-event-guarantees which basically saves eliminates the replay thrash a bit, but your reducer will need to handle some of that.

tldr: It's firebase, but I'll leave this in case someone needs it