https://github.com/RxSwiftCommunity/RxPager
Pager for RxSwift
https://github.com/RxSwiftCommunity/RxPager
Last synced: 5 months ago
JSON representation
Pager for RxSwift
- Host: GitHub
- URL: https://github.com/RxSwiftCommunity/RxPager
- Owner: RxSwiftCommunity
- License: mit
- Created: 2016-05-19T05:08:20.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-09-05T07:29:18.000Z (over 2 years ago)
- Last Synced: 2024-11-11T18:32:20.744Z (5 months ago)
- Language: Swift
- Size: 377 KB
- Stars: 60
- Watchers: 7
- Forks: 20
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rxswift - RxPager
README
# RxPager
[](https://travis-ci.org/RxSwiftCommunity/RxPager)
[](http://cocoapods.org/pods/RxPager)
[](http://cocoapods.org/pods/RxPager)
[](http://cocoapods.org/pods/RxPager)## Usage
```swift
// MARK: Example 1typealias Page = [Int]
typealias Callback = () -> Void// take previous Page, and create next one
let nextPage = { (previousPage: Page?) -> Observable in
let last = previousPage?.last ?? 0
return Observable.just([last + 1, last + 2, last + 3])
}// return true if there are more pages to be emitted
let hasNext = { (page: Page) -> Bool in
guard let last = page.last else { return true }
return last < 10 // arbitrary condition for the demo
}// create the pager
let trigger = PublishSubject()
let page$ = Observable.page(nextPage, while: hasNext, when: trigger)
let next = trigger.onNextpage$.subscribe(onNext: { print($0) })
// print [1, 2 ,3]next() // print [4, 5, 6]
next() // print [7, 8, 9]
next() // print [10, 11, 12]// MARK: Example 2 (page from array)
Observable
.page(Array(1...10), by: 3, when: trigger)
.subscribe(onNext: { print($0) })// print [1, 2 ,3]
next() // print [4, 5, 6]
next() // print [4, 5, 6]
next() // print [10]
```See [Demo](https://github.com/pgherveou/RxPager/blob/master/Example/RxPager/PagerTableViewController.swift) for more examples
## Example
To run the example project, or run the playground, clone the repo, and run `pod install` from the Example directory first.
## Requirements
## Installation
RxPager is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod "RxPager"
```## Credits
This pod is inspired by inspired by @mttkay work https://gist.github.com/mttkay/24881a0ce986f6ec4b4d
and was refactored using ideas discussed here https://github.com/RxSwiftCommunity/RxSwiftExt/issues/30## License
RxPager is available under the MIT license. See the LICENSE file for more info.