-
Notifications
You must be signed in to change notification settings - Fork 212
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
paginate operator #30
Comments
I'm not sure about this one. They may be as many pagination scenarios as there are applications using RxSwift -- deriving a generic operator may not be enough. While I think that pagination may be too specific in many cases to be generic, we could maybe explore ways to reverse the action by providing a static function like: extension Observable {
static public func paginate(requestFactory : (Int) -> Observable<E>, nextBatchTrigger : Observable<Void>)
-> Observable<E>
} There is a lot of boilerplate in the operator you're proposing, and if we can't manage to remove it then we may be failing at offering a useful operator. The solution I'm proposing above (at this stage I don't even suggest an implementation - just exploring the idea from a user's perspective) only requires the user to provide a factory function that returns an observable which provides one page of data (we pass an index, it returns an observable -- when the observable completes, all the data has been received for this page). The |
Yes, sure I agree that, there could be a lot of scenarios , and this was my concern :) But, what I was thinking about that, that generic
struct Batch {
let offset: Int
let limit: Int
let total: Int
let count: Int
}
struct UsersPage {
let batch: Batch
let users: [User]
} so in this case it would be
So in this case instead of
So { state in
switch state {
case .Repositories(repositories: _, nextUrl: let nextUrl):
return nextUrl != nil
default:
return false
}
}
Sure, it's not a full list of potential use cases, but what I'm pretty sure that you can always create some type, so you will be able on previous result determine whether it is possible to have next results or not. What do you think guys, am I missing something? :) |
Hey guys, |
@sergdort I refactored code here https://github.com/pgherveou/rxpager to build something similar from what you suggested, I am happy to send you guys a PR or keep it as it is in a separate pod |
I'm closing this for now due to inactivity - If you have any more comments on this subject, feel free to comment or ping me directly and I'll re-open it :) Thanks ! |
Name and description
Paginate operator
Motivation for inclusion
It was highly inspired by this tricky behavior in the RxExample 👍
The use case is pretty common (from my perspective), so I want to introduce operator which will provide this behavior
Proposed implementation
Example of use
P.S.
Still not sure about naming and whether it's could be applied for all scenarios
Wondering what you guys think about its inclusion?
The text was updated successfully, but these errors were encountered: