Swiftpack.co - Package - ukitaka/RxResponderChain

RxResponderChain

RxResponderChain is an extension of RxSwift, RxCocoa. It provides the way to notify Rx events via responder chain.

Usage

First, you have to create struct / class / enum represents event you want to notify using ResponderChainEvent protocol.

import RxResponder

struct LikeTweetEvent: ResponderChainEvent {
    let tweetID: Int64
}

Generate event object and pass it to bindTo (or, on, onNext … ).

final class TweetCell: UITableViewCell {
    ...

    override func awakeFromNib() {
        super.awakeFromNib()

        likeButton.rx.tap
            .map { _ in LikeTweetEvent(tweetID: self.tweet.id) }
            .bind(to:self.rx.responderChain)
            .disposed(by:disposeBag)
    }
}

Then you can receive events in classes that are on responder chain of the class sends events. For example, if you send event in UITableViewCell then you can receive them in tableView, viewController.view, viewController, viewController.navigationController, and so on.

final class TweetListViewController: UIViewController {
    ...

    override func viewDidLoad() {
        super.viewDidLoad()

        self.rx.responderChain.event(LikeTweetEvent.self)
            .flatMapFirst { e in twitterService.like(tweetID: e.tweetID) }
            .subscribe()
            .disposed(by:disposeBag)
    }
}

Requirements

RxResponderChain requires / supports the following environments:

  • Swift 3.1 / Xcode 8.3
  • iOS 9.0 or later
  • RxSwift / RxCocoa ~> 3.4

Installation

Carthage

github “ukitaka/RxResponderChain” ~> 1.1

CocoaPods

use_frameworks!
pod "RxResponderChain", "~> 1.1"

Github

link
Stars: 7
Help us keep the lights on

Dependencies

Used By

Total: 0