I’m using results of a sorted index to render a search results table. My index has 11 values + the ref as the last item, so it returns each item as an array of 12.
I’ve struggled figuring out how to paginate the index with
after but this question on SO indicated I should use the values as well with the ref. I managed it to work but my gut telling me I’m doing something hacky/wrong:
- Client (browser) receives results with
afterbeing an array(12)
- User clicks Load More
- Client does
JSON.stringify(after)and passes it to API on server side
- Server parses received param using
JSON.parseand got an array
- Server uses the same array but drops last element, and reconstruct it like:
[...array(11), q.Ref(q.Collection("coll"), ref["@ref"].id)]
- Pass the obtained value as
Now, as I mentioned this works, but my questions:
- Is JSON stringify/parse dance safe? Of course, I can pass those 11 values separately alongside with a ref but It would make the design brittle as it would unnecessarily couple the cursor to the values of index.
- I have already the ref as an object on the last element of the array. Can use it directly instead of extracting the id from it and basically reconstructing the same thing?
Hopefully I’m missing something quite obvious and I could simplify some bits of the flow.