This library is used with RxSwift to provide a easy way to handle paginated APIs. RxPagination is based on Action also.
- Only execute one trigger(reload/next/previous) at a time.
- Aggregates next/error events across individual executions.
3 separated pagination styles:
PagingAction
usespage
/itemsPerPage
OffsettingAction
usesoffset
/limit
CursoringAction
usesnext
/previous
let pagingAction: PagingAction<String, SampleResponse> = PagingAction<String, SampleResponse>(
itemsPerPage: 10,
removeDuplicates: { $0.id },
request: { (input, page) in
return api.getItems(for: input, page: page)
}
)
...
pagingAction.allItems.subscribe(onNext: { items in
print(items)
})
pagingAction.errors.subscribe(onError: { error in
print(error)
})
...
pagingAction.reload("Some Input")
pagingAction.next("Some Input")
Just add the line below to your Podfile:
pod 'RxPagination'
Then run pod install
and that'll be 👌
This library is inspired by dangthaison91, my colleague at VinID. And the implementation is based on RxCommunity's Action. Those developers deserve a lot of thanks!
MIT.