Skip to content

Instantly share code, notes, and snippets.

@Viveron
Last active December 14, 2018 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Viveron/729915739af8041ea40077a134985231 to your computer and use it in GitHub Desktop.
Save Viveron/729915739af8041ea40077a134985231 to your computer and use it in GitHub Desktop.
import UIKit
import LeadKit
import RxSwift
import RxCocoa
typealias TapTrait = Void
typealias TapRelay = PublishRelay<TapTrait>
typealias TapDriver = Driver<TapTrait>
extension PublishRelay where Element == TapTrait {
func tap() {
accept(())
}
func asDriver() -> TapDriver {
return asDriver(onErrorDriveWith: .empty())
}
}
extension SharedSequenceConvertibleType where SharingStrategy == DriverSharingStrategy, E == TapTrait {
func driveOnTap(_ closure: @escaping VoidBlock) -> Disposable {
return drive(onNext: closure)
}
}
@Viveron
Copy link
Author

Viveron commented Dec 14, 2018

let cancelTapRelay = TapRelay()

cancelTapRelay
    .asDriver()
    .driveOnTap {
        // code
    }
    .disposed(by: disposeBag)

cancelTapRelay.tap()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment