Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination support for all resources #37

Open
crazytonyli opened this issue Mar 8, 2024 · 3 comments
Open

Pagination support for all resources #37

crazytonyli opened this issue Mar 8, 2024 · 3 comments

Comments

@crazytonyli
Copy link
Contributor

It'd be nice to have a single pagination implementation for all resources. What do you all think?

let users = wordPressApi.paginate(User.self, orderBy: \.name)
let firstPage: [User] = try await users.nextPage()
let secondPage: [User] = try await users.nextPage()

// Same syntax can be used on Post
let posts = wordPressApi.paginate(Post.self, orderBy: \.modifiedDate)
let firstPage: [User] = try await posts.nextPage()
let secondPage: [User] = try await posts.nextPage()
@jkmassel
Copy link
Contributor

This is a really neat idea, though it'd need to be able to accept an arbitrary query as input – for instance, I might want to do something like:

let query = PostQuery(
  type: .custom("event"),
  context: .edit,
  modifiedAfter: Date().subtractingYears(1),
  orderBy: .modified,
  perPage: 100
)

let iterator = wordPressApi.paginate(User.self, using: query)

I also wonder if in this case the developer cares less about which page they're on, and more about knowing that they've retrieved all records? For instance, being able to iterate over all users instead of over pages of users?

WDYT?

@crazytonyli
Copy link
Contributor Author

I also wonder if in this case the developer cares less about which page they're on, and more about knowing that they've retrieved all records?

Probably not which page they're on. But I think they'll need the capability to load records page by page. For example, infinite scrolling posts list.

@crazytonyli
Copy link
Contributor Author

One thing I'm not sure of is, do we want (or is it feasible) to implement this shared pagination in rust, given we now mainly use WPApiHelper to build requests and parse responses?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants