{"id":20287038,"url":"https://github.com/magi82/rxviewbinder","last_synced_at":"2025-04-11T09:37:30.698Z","repository":{"id":62453250,"uuid":"125519918","full_name":"magi82/RxViewBinder","owner":"magi82","description":"RxViewBinder is a one-way architecture framework using Reactive.","archived":false,"fork":false,"pushed_at":"2020-07-07T15:38:07.000Z","size":64,"stargazers_count":32,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-26T15:01:54.393Z","etag":null,"topics":["architecture","reactive","rx","rxswift","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/magi82.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-16T13:28:37.000Z","updated_at":"2023-05-04T09:52:34.000Z","dependencies_parsed_at":"2022-11-01T23:46:34.272Z","dependency_job_id":null,"html_url":"https://github.com/magi82/RxViewBinder","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magi82%2FRxViewBinder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magi82%2FRxViewBinder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magi82%2FRxViewBinder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magi82%2FRxViewBinder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magi82","download_url":"https://codeload.github.com/magi82/RxViewBinder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248368706,"owners_count":21092436,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["architecture","reactive","rx","rxswift","swift"],"created_at":"2024-11-14T14:37:55.748Z","updated_at":"2025-04-11T09:37:30.676Z","avatar_url":"https://github.com/magi82.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RxViewBinder\n\n![Swift](https://img.shields.io/badge/Swift-5.0-orange.svg)\n[![Platform](https://img.shields.io/cocoapods/p/RxViewBinder.svg?style=flat)](http://cocoapods.org/pods/RxViewBinder)\n[![Version](https://img.shields.io/cocoapods/v/RxViewBinder.svg?style=flat)](http://cocoapods.org/pods/RxViewBinder)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![License](https://img.shields.io/cocoapods/l/RxViewBinder.svg?style=flat)](http://cocoapods.org/pods/RxViewBinder)\n\nRxViewBinder is a simple one-way architecture.\u003cbr\u003e\nSimple and easy to implement. :sunny:\n\nIt is implemented as a reactive extension.\n\n## Flow\n\n\u003cimg src=\"https://github.com/magi82/RxViewBinder/blob/master/Resources/flow.png?raw=true\"\u003e\n\n## Usage (ViewBindable)\n\n- Create a ViewBinder class that implements ViewBindable.\n\u003cbr\u003eCommand, Action, State must be implemented.\n\u003cbr\u003eCommand is enum type.\n\u003cbr\u003eAction, State is structure type.\n\n*important!!*\n\u003cbr\u003eYou need to bind the action and state in the constructor of the state structure.\n\n```swift\nfinal class SampleViewBinder: ViewBindable {\n  \n  enum Command {\n    case fetch\n  }\n  \n  struct Action {\n    let value: PublishRelay\u003cString\u003e = PublishRelay()\n  }\n  \n  struct State {\n    let value: Driver\u003cString\u003e\n    \n    init(action: Action) {\n      // Action and state binding\n      value = action.value.asDriver(onErrorJustReturn: \"\")\n    }\n  }\n  \n  let action = Action()\n  lazy var state = State(action: self.action)\n}\n```\n\n- implements a binding method that accepts a command stream and sends the stream to action.\n\u003cbr\u003eWhen changing the state of ui, only action is used.\n\u003cbr\u003estate is used only when the view receives the state of ui.\n\n```swift\n  func binding(command: Command) {\n    switch command {\n    case .fetch:\n      Observable\u003cString\u003e.just(\"test\")\n        .bind(to: action.value)\n        .disposed(by: self.disposeBag)\n    }\n  }\n```\n\n- Or you can simply send the stream without creating an observer.\n\n```swift\n  func binding(command: Command) {\n    switch command {\n    case .fetch:\n      action.value.accept(\"test\")\n    }\n  }\n```\n\n## Usage (BindView)\n\n- Implement the BindView protocol on the view controller.\n\u003cbr\u003eIt injects the view binder at initialization.\n\n```swift\nfinal class ViewController: UIViewController, BindView {\n\n  typealias ViewBinder = SampleViewBinder\n  \n  init(viewBinder: ViewBinder) {\n    defer { self.viewBinder = viewBinder }\n    \n    super.init(nibName: nil, bundle: nil)\n  }\n}\n```\n\n- If you are using a storyboard, you have to inject it in a different way.\n\n```swift\n  let vc = ViewController()\n  vc.viewBinder = SampleViewBinder()\n```\n\nor \n\n```swift\n  required init?(coder aDecoder: NSCoder) {\n    super.init(coder: aDecoder)\n    \n    self.viewBinder = ViewBinder()\n  }\n```\n\n- Implements the command and state methods.\n\n```swift\n  func command(viewBinder: ViewBinder) {\n    self.rx.methodInvoked(#selector(UIViewController.viewDidLoad))\n      .map { _ in ViewBinder.Command.fetch }\n      .bind(to: viewBinder.command)\n      .disposed(by: self.disposeBag)\n  }\n  \n  func state(viewBinder: ViewBinder) {\n    viewBinder.state\n      .value\n      .drive(onNext: { print($0) })\n      .disposed(by: self.disposeBag)\n  }\n```\n\n## Requirements\n\n- Swift 5.0+\n- iOS 9.0+\n\n## Installation\n\n- **For iOS 9+ projects** with [CocoaPods](https://cocoapods.org):\n\n```ruby\npod 'RxViewBinder', '~\u003e 2.0.0'\n```\n\n- **For iOS 9+ projects** with [Carthage](https://github.com/Carthage/Carthage):\n\n```ruby\ngithub \"magi82/RxViewBinder\" ~\u003e 2.0.0\n```\n\n## Author\n\nmagi82, devmagi82@gmail.com\n\n## License\n\n**RxViewBinder** is available under the MIT license. See the [LICENSE](LICENSE) file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagi82%2Frxviewbinder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagi82%2Frxviewbinder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagi82%2Frxviewbinder/lists"}