{"id":19593150,"url":"https://github.com/thoughtbot/bindings","last_synced_at":"2025-04-27T14:34:13.323Z","repository":{"id":66022030,"uuid":"205734278","full_name":"thoughtbot/Bindings","owner":"thoughtbot","description":"Unidirectional binding operators for Combine","archived":false,"fork":false,"pushed_at":"2021-09-24T16:14:25.000Z","size":21,"stargazers_count":41,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-05T00:51:18.121Z","etag":null,"topics":[],"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/thoughtbot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-01T21:27:11.000Z","updated_at":"2024-06-28T06:24:10.000Z","dependencies_parsed_at":"2023-02-23T10:15:15.519Z","dependency_job_id":null,"html_url":"https://github.com/thoughtbot/Bindings","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2FBindings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2FBindings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2FBindings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2FBindings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thoughtbot","download_url":"https://codeload.github.com/thoughtbot/Bindings/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251154988,"owners_count":21544582,"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":[],"created_at":"2024-11-11T08:38:21.624Z","updated_at":"2025-04-27T14:34:13.297Z","avatar_url":"https://github.com/thoughtbot.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# _Bindings_ for Combine\n\nUnidirectional binding operators and reactive extensions for Cocoa\nclasses.\n\n## The operators\n\n*Bindings* provides two operators: `\u003c~`, the **input binding operator**, and\n`~\u003e`, the **output binding operator**.\n\n### Input bindings update the state of your UI\n\n```swift\nimport Bindings\nimport UIKitBindings\n\nnameLabel.reactive.text \u003c~ viewModel.fullName\n```\n\n### Output bindings respond to changes\n\n```swift\nnameField.reactive.edited ~\u003e viewModel.setName\nUIApplication.reactive.didBecomeActiveNotification ~\u003e viewModel.refresh\n```\n\n## Common bindings for system classes\n\nIn addition to the core operator definitions, _Bindings_ also provides\nconveniences for using bindings with many system classes. Take a look at the\nfollowing modules to see what's provided (and consider\n[contributing][CONTRIBUTING]!):\n\n- [`UIKitBindings`][uikit] for apps using UIKit (iOS, iPadOS, Catalyst and more)\n- More to come...\n\n  [uikit]: /Sources/UIKitBindings\n\n## Reactive extensions\n\nIt's convenient to group reactive extensions into their own namespace,\nespecially when extending types you don't own with reactive APIs.\n\nUse the `ReactiveExtensionProvider` protocol to define the `.reactive` property\non your types:\n\n```swift\nextension MyViewModel: ReactiveExtensionProvider {}\n```\n\nThen add reactive extensions via the `Reactive` type:\n\n```swift\nextension UserDefaults {\n  var username: String? {\n    get { string(forKey: \"username\") }\n    set { set(newValue, forKey: \"username\") }\n  }\n}\n\nextension Reactive where Base: UserDefaults {\n  var username: NSObject.KeyValueObservingPublisher\u003cBase, String?\u003e {\n    base.publisher(for: \\.username)\n  }\n}\n\nUserDefaults.standard.reactive.username.sink { username in\n  print(\"New username: \\(username)\")\n}\n```\n\n## Bindings last for the lifetime of their owner\n\nIn Combine, the `AnyCancellable` class controls the lifetime of a subscription.\nSubscriptions can be automatically cancelled by using the `store(in:)` method:\n\n```swift\nimport UIKit\n\nclass MyViewController: UIViewController {\n  @IBOutlet private var usernameLabel: UILabel!\n  private var subscriptions: [AnyCancellable] = []\n\n  override func viewDidLoad() {\n    super.viewDidLoad()\n\n    UserDefaults.standard.reactive.username\n      .sink { [usernameLabel] in usernameLabel?.text = $0 }\n      .store(in: \u0026subscriptions)\n  }\n}\n```\n\n_Bindings_ encapsulates this pattern with the `BindingOwner` protocol, which\nautomatically defines a `subscriptions` collection on all conforming classes.\nThe `BindingSink` subscriber then automatically disposes of the binding\nsubscription when its `owner` goes out of scope:\n\n```swift\nextension Reactive where Base: UILabel {\n  var text: BindingSink\u003cBase, String?\u003e {\n    BindingSink(owner: base) { label, newValue in\n      label.text = newValue\n    }\n  }\n}\n\n// automatically cancelled when `usernameLabel` goes out of scope\nusernameLabel.reactive.text \u003c~ UserDefaults.standard.reactive.username\n```\n\n## Contributing\n\nHave a useful reactive extension in your project?\nPlease consider contributing it back to the community!\n\nFor more details, see the [CONTRIBUTING][] document.\nThank you, [contributors][]!\n\n  [CONTRIBUTING]: CONTRIBUTING.md\n  [contributors]: https://github.com/thoughtbot/Bindings/graphs/contributors\n\n## License\n\nBindings is Copyright (c) 2019 thoughtbot, inc.\nIt is free software, and may be redistributed\nunder the terms specified in the [LICENSE][] file.\n\n  [LICENSE]: /LICENSE\n\n## About\n\n![thoughtbot](http://presskit.thoughtbot.com/images/thoughtbot-logo-for-readmes.svg)\n\nBindings is maintained and funded by thoughtbot, inc.\nThe names and logos for thoughtbot are trademarks of thoughtbot, inc.\n\nWe love open source software!\nSee [our other projects][community]\nor [hire us][hire] to help build your product.\n\n  [community]: https://thoughtbot.com/community?utm_source=github\n  [hire]: https://thoughtbot.com/hire-us?utm_source=github\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtbot%2Fbindings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthoughtbot%2Fbindings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtbot%2Fbindings/lists"}