Modernizes doOn operator.
This commit is contained in:
parent
d1cde77b18
commit
441a4a22db
|
|
@ -120,6 +120,7 @@ extension DriverConvertibleType {
|
|||
- returns: The source sequence with the side-effecting behavior applied.
|
||||
*/
|
||||
// @warn_unused_result(message:"http://git.io/rxs.uo")
|
||||
@available(*, deprecated, renamed: "do(onNext:onError:onCompleted:)")
|
||||
public func doOn(_ eventHandler: (Event<E>) -> Void)
|
||||
-> Driver<E> {
|
||||
let source = self.asObservable()
|
||||
|
|
@ -137,6 +138,7 @@ extension DriverConvertibleType {
|
|||
- returns: The source sequence with the side-effecting behavior applied.
|
||||
*/
|
||||
// @warn_unused_result(message:"http://git.io/rxs.uo")
|
||||
@available(*, deprecated, renamed: "do(onNext:onError:onCompleted:)")
|
||||
public func doOn(onNext: ((E) -> Void)? = nil, onError: ((Swift.Error) -> Void)? = nil, onCompleted: (() -> Void)? = nil)
|
||||
-> Driver<E> {
|
||||
let source = self.asObservable()
|
||||
|
|
@ -152,9 +154,10 @@ extension DriverConvertibleType {
|
|||
- returns: The source sequence with the side-effecting behavior applied.
|
||||
*/
|
||||
// @warn_unused_result(message:"http://git.io/rxs.uo")
|
||||
public func `do`(onNext: ((E) -> Void))
|
||||
@available(*, deprecated, renamed: "do(onNext:)")
|
||||
public func doOnNext(_ onNext: ((E) -> Void))
|
||||
-> Driver<E> {
|
||||
return self.doOn(onNext: onNext)
|
||||
return self.do(onNext: onNext)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -164,9 +167,27 @@ extension DriverConvertibleType {
|
|||
- returns: The source sequence with the side-effecting behavior applied.
|
||||
*/
|
||||
// @warn_unused_result(message:"http://git.io/rxs.uo")
|
||||
public func `do`(onCompleted: (() -> Void))
|
||||
@available(*, deprecated, renamed: "do(onCompleted:)")
|
||||
public func doOnCompleted(_ onCompleted: (() -> Void))
|
||||
-> Driver<E> {
|
||||
return self.doOn(onCompleted: onCompleted)
|
||||
return self.do(onCompleted: onCompleted)
|
||||
}
|
||||
|
||||
/**
|
||||
Invokes an action for each event in the observable sequence, and propagates all observer messages through the result sequence.
|
||||
|
||||
- parameter onNext: Action to invoke for each element in the observable sequence.
|
||||
- parameter onError: Action to invoke upon errored termination of the observable sequence. This callback will never be invoked since driver can't error out.
|
||||
- parameter onCompleted: Action to invoke upon graceful termination of the observable sequence.
|
||||
- returns: The source sequence with the side-effecting behavior applied.
|
||||
*/
|
||||
// @warn_unused_result(message:"http://git.io/rxs.uo")
|
||||
public func `do`(onNext: ((E) -> Void)? = nil, onError: ((Swift.Error) -> Void)? = nil, onCompleted: (() -> Void)? = nil)
|
||||
-> Driver<E> {
|
||||
let source = self.asObservable()
|
||||
.doOn(onNext: onNext, onError: onError, onCompleted: onCompleted)
|
||||
|
||||
return Driver(source)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ extension DelegateProxyType {
|
|||
}
|
||||
|
||||
extension ObservableType {
|
||||
func subscribeProxyDataSourceForObject<P: DelegateProxyType>(_ object: AnyObject, dataSource: AnyObject, retainDataSource: Bool, binding: (P, Event<E>) -> Void)
|
||||
func subscribeProxyDataSource<P: DelegateProxyType>(ofObject object: AnyObject, dataSource: AnyObject, retainDataSource: Bool, binding: (P, Event<E>) -> Void)
|
||||
-> Disposable {
|
||||
let proxy = P.proxyForObject(object)
|
||||
let disposable = P.installForwardDelegate(dataSource, retainDelegate: retainDataSource, onProxyForObject: object)
|
||||
|
|
@ -275,4 +275,4 @@ extension ObservableType {
|
|||
|
||||
return CompositeDisposable(subscription, disposable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ extension UICollectionView {
|
|||
-> Disposable {
|
||||
return { source in
|
||||
|
||||
return source.subscribeProxyDataSourceForObject(self, dataSource: dataSource, retainDataSource: true) { [weak self] (_: RxCollectionViewDataSourceProxy, event) -> Void in
|
||||
return source.subscribeProxyDataSource(ofObject: self, dataSource: dataSource, retainDataSource: true) { [weak self] (_: RxCollectionViewDataSourceProxy, event) -> Void in
|
||||
guard let collectionView = self else {
|
||||
return
|
||||
}
|
||||
|
|
@ -281,7 +281,7 @@ extension UICollectionView {
|
|||
-> Disposable {
|
||||
return { source in
|
||||
|
||||
return source.subscribeProxyDataSourceForObject(self, dataSource: dataSource, retainDataSource: true) { [weak self] (_: RxCollectionViewDataSourceProxy, event) -> Void in
|
||||
return source.subscribeProxyDataSource(ofObject: self, dataSource: dataSource, retainDataSource: true) { [weak self] (_: RxCollectionViewDataSourceProxy, event) -> Void in
|
||||
guard let collectionView = self else {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -226,7 +226,7 @@ extension UITableView {
|
|||
-> Disposable {
|
||||
return { source in
|
||||
// There needs to be a strong retaining here because
|
||||
return source.subscribeProxyDataSourceForObject(self, dataSource: dataSource, retainDataSource: true) { [weak self] (_: RxTableViewDataSourceProxy, event) -> Void in
|
||||
return source.subscribeProxyDataSource(ofObject: self, dataSource: dataSource, retainDataSource: true) { [weak self] (_: RxTableViewDataSourceProxy, event) -> Void in
|
||||
guard let tableView = self else {
|
||||
return
|
||||
}
|
||||
|
|
@ -288,7 +288,7 @@ extension UITableView {
|
|||
-> Disposable {
|
||||
return { source in
|
||||
// There needs to be a strong retaining here because
|
||||
return source.subscribeProxyDataSourceForObject(self, dataSource: dataSource, retainDataSource: true) { [weak self] (_: RxTableViewDataSourceProxy, event) -> Void in
|
||||
return source.subscribeProxyDataSource(ofObject: self, dataSource: dataSource, retainDataSource: true) { [weak self] (_: RxTableViewDataSourceProxy, event) -> Void in
|
||||
guard let tableView = self else {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ extension ObservableType {
|
|||
- returns: The source sequence with the side-effecting behavior applied.
|
||||
*/
|
||||
// @warn_unused_result(message:"http://git.io/rxs.uo")
|
||||
@available(*, deprecated, renamed: "do(onNext:onError:onCompleted:)")
|
||||
public func doOn(_ eventHandler: (Event<E>) throws -> Void)
|
||||
-> Observable<E> {
|
||||
return Do(source: self.asObservable(), eventHandler: eventHandler)
|
||||
|
|
@ -100,6 +101,7 @@ extension ObservableType {
|
|||
- returns: The source sequence with the side-effecting behavior applied.
|
||||
*/
|
||||
// @warn_unused_result(message:"http://git.io/rxs.uo")
|
||||
@available(*, deprecated, renamed: "do(onNext:onError:onCompleted:)")
|
||||
public func doOn(onNext: ((E) throws -> Void)? = nil, onError: ((Swift.Error) throws -> Void)? = nil, onCompleted: (() throws -> Void)? = nil)
|
||||
-> Observable<E> {
|
||||
return Do(source: self.asObservable()) { e in
|
||||
|
|
@ -121,9 +123,10 @@ extension ObservableType {
|
|||
- returns: The source sequence with the side-effecting behavior applied.
|
||||
*/
|
||||
// @warn_unused_result(message:"http://git.io/rxs.uo")
|
||||
public func `do`(onNext: ((E) throws -> Void))
|
||||
@available(*, deprecated, renamed: "do(onNext:)")
|
||||
public func doOnNext(onNext: ((E) throws -> Void))
|
||||
-> Observable<E> {
|
||||
return self.doOn(onNext: onNext)
|
||||
return self.do(onNext: onNext)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -133,9 +136,10 @@ extension ObservableType {
|
|||
- returns: The source sequence with the side-effecting behavior applied.
|
||||
*/
|
||||
// @warn_unused_result(message:"http://git.io/rxs.uo")
|
||||
public func `do`(onError: ((Swift.Error) throws -> Void))
|
||||
@available(*, deprecated, renamed: "do(onError:)")
|
||||
public func doOnError(onError: ((Swift.Error) throws -> Void))
|
||||
-> Observable<E> {
|
||||
return self.doOn(onError: onError)
|
||||
return self.do(onError: onError)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -145,9 +149,35 @@ extension ObservableType {
|
|||
- returns: The source sequence with the side-effecting behavior applied.
|
||||
*/
|
||||
// @warn_unused_result(message:"http://git.io/rxs.uo")
|
||||
public func `do`(onCompleted: (() throws -> Void))
|
||||
@available(*, deprecated, renamed: "do(onCompleted:)")
|
||||
public func doOnCompleted(onCompleted: (() throws -> Void))
|
||||
-> Observable<E> {
|
||||
return self.doOn(onCompleted: onCompleted)
|
||||
return self.do(onCompleted: onCompleted)
|
||||
}
|
||||
|
||||
/**
|
||||
Invokes an action for each event in the observable sequence, and propagates all observer messages through the result sequence.
|
||||
|
||||
- seealso: [do operator on reactivex.io](http://reactivex.io/documentation/operators/do.html)
|
||||
|
||||
- parameter onNext: Action to invoke for each element in the observable sequence.
|
||||
- parameter onError: Action to invoke upon errored termination of the observable sequence.
|
||||
- parameter onCompleted: Action to invoke upon graceful termination of the observable sequence.
|
||||
- returns: The source sequence with the side-effecting behavior applied.
|
||||
*/
|
||||
// @warn_unused_result(message:"http://git.io/rxs.uo")
|
||||
public func `do`(onNext: ((E) throws -> Void)? = nil, onError: ((Swift.Error) throws -> Void)? = nil, onCompleted: (() throws -> Void)? = nil)
|
||||
-> Observable<E> {
|
||||
return Do(source: self.asObservable()) { e in
|
||||
switch e {
|
||||
case .next(let element):
|
||||
try onNext?(element)
|
||||
case .error(let e):
|
||||
try onError?(e)
|
||||
case .completed:
|
||||
try onCompleted?()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue