{"id":17188237,"url":"https://github.com/jclem/tentjs-rails","last_synced_at":"2025-03-25T04:39:55.924Z","repository":{"id":3713584,"uuid":"4785521","full_name":"jclem/tentjs-rails","owner":"jclem","description":"Tent.js is a lightweight set of extensions on top of Backbone.js","archived":false,"fork":false,"pushed_at":"2012-06-26T20:01:12.000Z","size":172,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T10:52:53.854Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"github.com/jclem/tentjs-rails","language":"JavaScript","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/jclem.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":"2012-06-25T18:27:47.000Z","updated_at":"2013-11-28T02:49:12.000Z","dependencies_parsed_at":"2022-09-01T08:20:12.462Z","dependency_job_id":null,"html_url":"https://github.com/jclem/tentjs-rails","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jclem%2Ftentjs-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jclem%2Ftentjs-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jclem%2Ftentjs-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jclem%2Ftentjs-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jclem","download_url":"https://codeload.github.com/jclem/tentjs-rails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245401374,"owners_count":20609163,"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-15T01:08:28.242Z","updated_at":"2025-03-25T04:39:55.905Z","avatar_url":"https://github.com/jclem.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tentjs-rails\n\nTent.js is a lightweight structure built on top of Backbone.js\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'tentjs-rails'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install tentjs-rails\n\n## Using Tent\n\nRather than extending Backbone prototypes directly, Tent builds on top of them. That way, you can still create vanilla Backbone View, Models, and Collections without the additions that Tent provides. So, creating a view that uses Tent's extensions looks like this:\n\n```\nview = new Tent.View();\n```\n\n## Tent.App\n\n`Tent.App` is a very basic module that includes an internal reference to `Tent.Dispatcher` and fires a `tent:app:started` event when its `start` function is called.\n\n```\nwindow.Application = new Tent.App();\n```\n\n## Tent.Collection and Tent.Model\n\n`Tent.Collection` and `Tent.Model` are exactly like a `Backbone.Collection` and `Backbone.Model`, respectively, except that they each have a `serialize` function which calls `JSON.stringify` on the result of their `toJSON` functions.\n\n## Tent.PubSub\n\nTent includes a handy global event dispatcher called `Tent.Dispatcher`. Anything that includes the `Tent.PubSub` module is able to communicate with this dispatcher like so:\n\n### Subscribing to events\n\nThe `subscribe` function ensures that a callback is fired when the dispatcher sees the specified event.\n\n```\nview.subscribe('some:event', view.doSomething)\n```\n\n### Unsubscribing from events\n\nCalling `unsubscribe` with an event and a callback unsubscribes that callback from the specified event. Specifying a callback with no event unsubscribes that callback from all events. Specifying an event with no callback unsubscribes all callbacks from that event for the calling object. Calling `unsubscribe` with no arguments unsubscribes the calling object completely from the dispatcher events.\n\n```\nview.unsubscribe('an:event', view.doSomething);\nview.unsubscribe(null, view.doSomething);\nview.unsubscribe('an:event');\nview.unsubscribe();\n```\n\n### Publishing events\n\nAn object can publish events to the dispatcher using `publish`.\n\n```\nview.publish('some:event', anArgument, anotherArgument);\n```\n\n### Using Tent.PubSub\n\nTo include Tent.PubSub in an object prototype:\n\n```\n_.extend(Something.prototype, Tent.PubSub);\n```\n\n## Tent.View\n\n### Binding to an object\n\nBy binding to an object using the `view.bindTo()` function, one can ensure that the binding is released when the view is closed using Tent's `view.close()` function.\n\n```\nview.bindTo(view.model, 'change', view.doSomething);\n```\n\n`bindTo` limits you to using the calling object as the context, which makes unbinding easier. If you must use another object as the context for a binding callback, use Backbone's `on` function.\n\n\n### Unbinding from an object\n\nUnbinding from an object is done with `unbindFrom`:\n\n```\nview.unbindFrom(view.model);\n```\n\n### Releasing all bindings\n\nWhen closing a view, Tent's `close` function takes care of releasing bindings made with `bindTo`, but the bindings can also all be released with `unbindAll`.\n\n```\nview.unbindAll();\n```\n\n### Closing a view\n\nCalling `view.close()` will do a fiew things:\n\n1. Call `view.beforeClose()` if it's been defined.\n2. Call `view.unbindAll()` to get rid of bindings.\n3. Call `view.off()` to get rid of DOM bindings.\n4. Call `view.remove()` to remove the view DOM element itself.\n\n## Tent.ModelView\n\n### Initializing\n\n`Tent.ModelView` has its own `initialize` function, so you'll want to make sure that when overriding it, you'll generally want to still use the built-in function:\n\n```\nApplication.SomeModelView = Tent.ModelView.extend({\n  initialize: function () {\n    Tent.ModelView.prototype.initialize.apply(this, arguments);\n    // ...\n  }\n});\n```\nWhen a `Tent.ModelView` initializes, it sets an attribute called `data-model-cid` on its element whose value is the `cid` of the instance of `Tent.Model`* that was passed into the constructor:\n\n```\nvar model = new Tent.Model();\nvar view = new Tent.ModelView({ model: model });\nview.el.getAttribute('data-model-cid'); // === model.cid\n```\n\nThe element also gets an attribute called `data-model-attributes` that contains a serialized version of all of the model's attributes (note that this uses the `Tent.Model.prototype.serialize` function).\n\n\\* `Tent.ModelView` will only initialize properly when passed an instance a `Tent.Model`.\n\n### Changing the model\n\n`Tent.ModelView` will update its `data-model-attributes` and re-render when the model's `change` event is fired.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjclem%2Ftentjs-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjclem%2Ftentjs-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjclem%2Ftentjs-rails/lists"}