Open mesqueeb opened 5 years ago
As far as I know it's not possible to request x docs with an offset of y. ↳ this means it's not possible for a user to suddenly request page 10 skipping page 1-9.
In my library I save the last doc ref to be able to retrieve the next set of docs each time:
// inside the `fetch` action
const lastVisible = docs[docs.length - 1]
// get the next records reference.
const next = fRef.startAfter(lastVisible)
Does anyone know how to work around this firestore limitation when trying to create paging support? Does anyone have any ideas?
I can save each set of results under a page-name sure, but the user could never skip more than 1 page of results you see.
Also see this video where the firebase guys explain that limitation: https://youtu.be/IdKEhWAV-kE?t=37
@BenAHammond
My thought is basically this: You cannot actually overcome the limitations of the firebase API, but you can obfuscate them with your own API that does the fetching in the background.
So, for instance, you could create a paged_list
type collection that keeps a hidden subcollection of all of the data and exposes fields for the current page, the current subset of data, and functions to trigger fetches for whatever pages the user needs.
Make it really easy for users of this library to page, even if it sucks to fetch each row by hand in the background.
Here's an update from the firebase youtube videos, released today: https://www.youtube.com/watch?v=poqTHxtDXwU
I understood everything he said and literally learned nothing... : D He basically says probably the best way to do it is how I'm already doing it in my library, where I work with last document reference.
I guess I could improve the library to save the data in an object with page numbers as well. Then when the consumer skips 2 pages my library makes the skipped fetches as well but you could immediately show the third page in the UI. Meaning there's no additional loading required going back a page.
Please also note my library only has the fetch next results with the fetchAndAdd
method, which I'm willing to improve on.
However, if anyone needs realtime listeners (openDBChannel) with pagination support, they're better off making their own solution or help me by PR'ing the library. ^^
Planned pagination support for
fetchAndAdd
andfetch
After about two years of open source, I finally got accepted for Github Sponsors!
💜 github.com/sponsors/mesqueeb 💜
A little about me:
If anyone was helped with vuex-easy-firestore, I'd greatly appreciate any support!
Going forward 👨🏼💻