Fork me on GitHub
#fulcro
<
2018-05-30
>
myguidingstar06:05:11

@tony.kay @wilkerlucio say I want to use pagination in comments of blog post as we discussed yesterday. Assume the subquery params problem has been resolved, I still can't think of anyway to compose queries from Comments to Paginated Comment List up to Blog component

myguidingstar06:05:31

the Pagination pattern works well for top level lists, but I can't find an obvious way for nested lists like Comments

wilkerlucio13:05:14

@myguidingstar just from the top of my head, what I would do is something like GraphQL does, have some context around the paginated resource (another component), which tracks the page status (next page, all items, current page...), but never tried, seems an interesting experiment

myguidingstar13:05:24

the problem is Blog and Comment have their place in both client db and server while Pagination is only client side. That's why I find composing queries for them cumbersome

wilkerlucio13:05:10

you can re-structure your server as well

wilkerlucio13:05:32

instead of having just {:post/comments [:comment/id :comment/text ...]}, make something more structured, like:

wilkerlucio13:05:23

{:post/paginated-comments [:page/next-page-token :page/total-items :page/current-page {:page/items [:comment/id :comment/text ...]}]

tony.kay13:05:18

@myguidingstar it could be you’re relying on parameters in queries more than I would. I tend to use state for pagination, not queries.

myguidingstar14:05:14

@tony.kay I don't get it. Can you give a little more details?

tony.kay14:05:06

Like the pagination example in the book

tony.kay14:05:36

use :ui/page and such as attributes on the UI component, and write mutations that manage the pages.

myguidingstar14:05:12

I just think it would be great if Fulcro support pagination first class 😄

👍 4
myguidingstar14:05:09

so app developers don't have to care too much about the details

tony.kay14:05:19

@myguidingstar There are so many ways of doing pagination and caching. It doesn’t really make sense to put it in the main library I don’t think…it is already pushing it in some areas. An add-on library would be nice, though, for some common ways of doing it 🙂

tony.kay14:05:27

I mean, one way of “doing it” is just to load “all”, and then paginate in the UI component itself with sort, drop, and take.

tony.kay14:05:54

another is to do a sliding window of storage on the client (for large lists)

tony.kay14:05:25

another is the “show what I have so far, and load more when I get to the bottom of scrolling”

tony.kay14:05:50

pagination could easily be a library the size of Fulcro

mitchelkuijpers14:05:52

I can recommend the approach from the book we use that too and it has served us well. If you use nice idents per :ui/page then you can also do easy caching

myguidingstar15:05:23

@mitchelkuijpers is your paginated list living in top level of app state (like Blog) or nested (like Comment)?

mitchelkuijpers15:05:22

We create an ident like this:

(fn [] [:page/by-pagination {:page/start start
                                       :page/size size
                                       :page/type type}])

mitchelkuijpers15:05:24

It doesn't really matter if it's nested for us you could just add an extra thing such as comment-page/by-pagination which also includes the blog-id

myguidingstar15:05:16

yeah, I make such "combo" idents as well. And I use defrecord for better performance and to avoid error

myguidingstar15:05:21

but I don't like the way a lot of mutations around load

mitchelkuijpers15:05:38

Why not? it's just some simple state

mitchelkuijpers15:05:07

It's is really testable and boring which is perfect in my opinion

myguidingstar15:05:16

okay, I'll look at it later. Thanks for sharing it

mitchelkuijpers15:05:01

I wouldn't fiddle with subqueries to be honest

myguidingstar15:05:22

I did read that 😉

mitchelkuijpers16:05:44

Oh now I get the subqueries, I just read some older comments. I thought you were talking about dynamic queries. So don't listen to me on that part facepalm

🙂 4
levitanong19:05:12

@mitchelkuijpers shouldn’t the load in there be using load-action instead, since it’s called from within a mutation?