Skip to content
Pager for RxSwift
Branch: master
Clone or download
AYastrebov and pgherveou Update podspec to support RxSwift 4.0 (#2)
* Update podspec to support RxSwift 3.2.0+

* - update to rxsift 3.6.1

* - update to swift 4 and rxswift 4

* - fix travis
Latest commit 027ad5c Oct 30, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example
RxPager.playground
RxPager/Classes
docs
.gitignore
.swift-version Update podspec to support RxSwift 4.0 (#2) Oct 30, 2017
.swiftlint.yml
.travis.yml Update podspec to support RxSwift 4.0 (#2) Oct 30, 2017
LICENSE Update LICENSE Jan 31, 2017
Makefile Fix makefile Jan 24, 2017
README.md
RxPager.podspec
_Pods.xcodeproj

README.md

RxPager

CI Status Version License Platform

Usage

// MARK: Example 1

typealias Page = [Int]
typealias Callback = () -> Void

// take previous Page, and create next one
let nextPage = { (previousPage: Page?) -> Observable<Page> 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<Void>()
let page$ = Observable.page(nextPage, while: hasNext, when: trigger)
let next = trigger.onNext

page$.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 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. To install it, simply add the following line to your Podfile:

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.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.