redux-firestore
redux-firestore copied to clipboard
feat(query) enable support for DocumentSnapshot with start/endAt
What is the feature?
enable passing a DocumentSnapshot
to a query
https://firebase.google.com/docs/reference/js/firebase.firestore.Query#start-at
Do you have thoughts/examples on how the feature would be used (i.e. API)?
I'm trying to implement a table that allows me to page through the documents returned by a query. Because of duplication of properties of the documents I cannot reliable use these properties to paginate. I need to use startAt
/endAt
with an actual DocumentSnapshot
passed to ensure I am not missing any documents. This behaviour is talked about in the firestore docs
There is the snapshot cache that was added by @illuminist in v0.11.0 - that should be useful for doing this, just haven't written up an example yet
Thanks for pointing that out @prescottprue. I tried using that code, but after passing getSnapshotFromObject
the data for a particular object instead of returning a DocumentSnapshot
, it returns a QuerySnapshot
.
@goleary Thanks for reaching out - I reached out to @illumnist over gitter for more detail.
How did you end up using it? Would you mind sharing the app logic?
looking into that WeakMap
this is what I see:
It looks like I can access the DocumentSnapshot
, but I assumed it would be a littler easier/simpler than this. Everything in the WeakMap
is a QuerySnapshot
.
so if I obtain the DocumentSnapshot
as such:
I am able to pass it to
startAfter
, but something seems off. The WeakMap
contains quite a bit of duplicated data (the same QuerySnapshot
and 10 DocumentSnapshots
for each of the documents within that query).
Thank you @goleary
I have found my mistake. I set document data as a key for QuerySnapshot instead of intended DocumentSnapshot. I even forgot to add the responding unit test to test if snapshot is right for the inner data.
PR https://github.com/prescottprue/redux-firestore/pull/258
@illuminist Thanks a bunch for looking into it and making the PR!
@prescottprue I found a new problem where updating QuerySnapshot isn’t update along with WeakMap key. The new ordered array and a data object is being created inside of reducer where I couldn’t access snapshot, and passing snapshot with action is against redux rules. One possible solution is to reduce the whole state inside of action creator and pass that entire data and ordered object into action instead. The DocumentSnapshot for pagination is still fine though.
So what is your thought?