jschomay / elm-paginate

Simple and robust pagination in elm

Home Page:http://package.elm-lang.org/packages/jschomay/elm-paginate/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Have Pager wrap the data to be paginated

jschomay opened this issue · comments

It's alway bothered me that Pager stores duplicated derived state (the length of the list to paginate). This creates the situation where those two values can get out of sync and require manual management to keep them in sync.

Perhaps a better type would be Pager a, where init takes the page size and a List a, and keeps everything in sync itself. You would need to use map to change the list inside the Pager (and remove update). This breaks the idea that paging is a display concern only, and explicitly binds the concept of paging to your data in your domain, but maybe that is a good thing?

(For semantics, toList should probably be renamed to render because it renders the pager, not the list. Should getList or fullList be added to remove the Pager wrapper? I don't think that would ever make sense doing?)

After further thought, the pager can work with a List by default (or maybe an Array is better?), but Pager.Custom would expose an init that takes any type plus a length and slice function, which would allow you to use any aggregate types, or more helpfully, a custom opaque type that wraps some kind of list.

The new types should be PaginatedList a and Paginated a where a would be a custom collection like LazyList String (note that lazy lists would be a cool thing to paginate).

Also, the toList and page functions would move under "Rendering" as pager and page.