{"id":17774503,"url":"https://github.com/nathankot/motion-bindable","last_synced_at":"2025-04-21T23:31:30.266Z","repository":{"id":12459226,"uuid":"15122145","full_name":"nathankot/motion-bindable","owner":"nathankot","description":"A simple two-way data binding library for RubyMotion.","archived":false,"fork":false,"pushed_at":"2014-03-19T05:05:24.000Z","size":706,"stargazers_count":11,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-26T22:47:36.873Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"bingoogolapple/BGABadgeView-Android","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nathankot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-11T23:30:44.000Z","updated_at":"2018-03-11T16:17:25.000Z","dependencies_parsed_at":"2022-09-09T02:50:21.009Z","dependency_job_id":null,"html_url":"https://github.com/nathankot/motion-bindable","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathankot%2Fmotion-bindable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathankot%2Fmotion-bindable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathankot%2Fmotion-bindable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathankot%2Fmotion-bindable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nathankot","download_url":"https://codeload.github.com/nathankot/motion-bindable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223881648,"owners_count":17219268,"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-10-26T21:51:05.426Z","updated_at":"2024-11-09T21:02:21.133Z","avatar_url":"https://github.com/nathankot.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Motion Bindable\n\n[![Build Status](https://travis-ci.org/nathankot/motion-bindable.png?branch=master)](https://travis-ci.org/nathankot/motion-bindable)\n[![Code Climate](https://codeclimate.com/github/nathankot/motion-bindable.png)](https://codeclimate.com/github/nathankot/motion-bindable)\n\nA simple two-way data binding library for RubyMotion.\n\n## NOTICE\n\nVersion `0.3.0` introduces breaking changes and deprecations. If you're upgrading, please check the [release\nnotes](https://github.com/nathankot/motion-bindable/releases/tag/v0.3.0).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'motion_bindable'\n```\n\nAnd then execute:\n\n```sh\n$ bundle\n```\n\nIf you want to use the default strategies that come with MotionBindable add\nthis to your `app_delegate.rb`:\n\n``` ruby\ndef application(application, didFinishLaunchingWithOptions: launch_options)\n  MotionBindable::Strategies.apply\n  true\nend\n```\n\n## Terminology\n\n| Name    | Definition                                                                                                             |\n| ---     | ---                                                                                                                    |\n| Object  | Refers to the _parent_ object that can have many bindings. Usually a model of some sort.                               |\n| Binding | The connection between an object and it's bound children. Observes and updates both sides. Represented as a `Strategy` |\n| Bound   | Usually an _input_ object, like a `UITextField` or a `Proc`.                                                           |\n\n## Usage\n\nAdd `include MotionBindable::Bindable` to make an object bindable:\n\n```ruby\n# Models\n\nclass Item\n  include MotionBindable::Bindable\n  attr_accessor :name\n  attr_accessor :location\n\n  def location\n    @address ||= Address.new\n  end\nend\n\nclass Address\n  attr_accessor :address\nend\n```\n\nIn your view controller, you can bind the object to a set of Views or any\nother object:\n\n```ruby\nclass ItemListViewController\n  def viewDidLoad\n    super\n    @name_field = UITextField.alloc.initWithFrame [[110, 60], [100, 26]]\n    @name_field.placeholder = \"Name\"\n    view.addSubview @name_field\n\n    @address_field = UITextField.alloc.initWithFrame [[110, 100], [100, 26]]\n    @address_field.placeholder = \"Address\"\n    view.addSubview @address_field\n\n    @item = Item.new\n  end\n\n  def viewWillAppear(animated)\n    @item.bind_attributes({\n      name: @name_field,\n      location: {\n        address: @address_field\n      }\n    })\n  end\n\n  # Recommended: Clean everything up when the view leaves\n  def viewWillDisappear(animated)\n    @item.unbind_all\n  end\nend\n```\n\nWhen `@name_field.text` or `@address_field.text` changes, so will your model!\n\n### Custom Strategies\n\nThe above example uses the `MotionBindable::Strategies::UITextField`.  which\ncomes with MotionBindable. Take a look in `lib/motion_bindable/strategies` for\nthe available defaults. You can implement your own strategies by extending\n`MotionBindable::Strategy`. Please use the existing strategies as a guideline.\n\n### Default Strategies\n\nThe following strategies come with motion-bindable and are setup when\n`MotionBindable::Strategies.apply` is called.\n\n| Name                                      | Object Candidates | Direction           |\n| ----------------------------------------- | ----------------- | ------------------- |\n| `MotionBindable::Strategies::UITextField` | Any `UITextField` | Bound \u003c-\u003e Attribute |\n| `MotionBindable::Strategies::Proc`        | Any `Proc`        | Bound --\u003e Attribute |\n| `MotionBindable::Strategies::UILabel`     | Any `UILabel`     | Bound \u003c-- Attribute |\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathankot%2Fmotion-bindable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnathankot%2Fmotion-bindable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathankot%2Fmotion-bindable/lists"}