re-frame-firebase icon indicating copy to clipboard operation
re-frame-firebase copied to clipboard

Telling the difference between a loading data, [], and, missing data

Open shen-tian opened this issue 6 years ago • 3 comments

This is to do with the behaviour of the on-value sub:

Right now, if the realtime db looked like this:

{
   "foo": {
      "bar": "x",
      "baz": []
   }
}
  • @(subscribe [:fireabase/on-value {:path [:foo :bar]}]) first take the value [] when the subscription is first created, and then, once fetched from server, give "x".
  • @(subscribe [:fireabase/on-value {:path [:foo :baz]}]) first take the value [] when the subscription is first created, and remains that way as the empty array is fetched.
  • @(subscribe [:fireabase/on-value {:path [:foo :qux]}]) first take the value [] when the subscription is first created, and remains that way as it's detected as missing.

The first case, where we know the data to be present, and not [], works fine for things like "loading" screens (i.e. Nine state of design stuff).

The second case doesn't work, as nothing changes between "loading" and "loaded and empty". We can avoid this in db schema design (i.e. use maps not vectors?).

The third case is more tricky, because you can't tell between "loading" and "missing".

Any ideas on how to proceed? I suspect that changing the default value on this line from [] to something else (::pending?) could be a solution, but would be a breaking change

https://github.com/deg/re-frame-firebase/blob/216595bab8e392caee1233a6480495d610b7a215/src/com/degel/re_frame_firebase/database.cljs#L63-L66

shen-tian avatar Oct 31 '18 15:10 shen-tian

Sorry for my long delay; I missed this message. I'm not actively working with Firebase right now, so I don't have much to add to your analysis. Have you gotten further in thinking about this?

deg avatar Feb 03 '19 19:02 deg

It's been a while, but worth an update. This particular behaviour has caused quite a few bugs in our system in the last few month. We are dealing with it by explicitly checking for subscriptions deref-ing to []. This doesn't solve the "actually [] case, of course, but works in our system.

shen-tian avatar Jul 17 '19 09:07 shen-tian

My apologies. It will be at least another few weeks before I will be able to look at this project.

deg avatar Jul 17 '19 09:07 deg