{"id":20724656,"url":"https://github.com/arhea/backbone-deferred","last_synced_at":"2025-04-23T18:05:02.752Z","repository":{"id":7741347,"uuid":"9108198","full_name":"arhea/backbone-deferred","owner":"arhea","description":"An implementation of Backbone Model and Collection using the promise pattern rather than passing callback options. Supports popular deferred libraries like Q and jQuery.","archived":false,"fork":false,"pushed_at":"2014-11-20T00:34:57.000Z","size":10074,"stargazers_count":46,"open_issues_count":2,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-23T18:04:54.967Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/arhea.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":"2013-03-29T22:58:45.000Z","updated_at":"2018-10-02T21:17:29.000Z","dependencies_parsed_at":"2022-07-08T03:20:36.479Z","dependency_job_id":null,"html_url":"https://github.com/arhea/backbone-deferred","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/arhea%2Fbackbone-deferred","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arhea%2Fbackbone-deferred/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arhea%2Fbackbone-deferred/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arhea%2Fbackbone-deferred/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arhea","download_url":"https://codeload.github.com/arhea/backbone-deferred/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250487530,"owners_count":21438612,"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-17T04:15:52.416Z","updated_at":"2025-04-23T18:05:02.734Z","avatar_url":"https://github.com/arhea.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"##Backbone Deferred\n[![Build Status](https://travis-ci.org/arhea/backbone-deferred.png)](https://travis-ci.org/arhea/backbone-deferred)\n[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)\n\nThis library converts models and collections to use the deferred pattern. So instead of returning the raw jQuery XHR object from a fetch, save, or destroy. This library allows you to access all the same functionality provided by the success and error callbacks with the nice deferred pattern.\n\n```javascript\nmodel.save();\n```\n\n###Examples\n```javascript\nvar model = new Model({ id: 1 });\n\nmodel.fetch({\n    success: function(model, response, options) {\n        alert('Yay!');\n    },\n    error: function(model, xhr, options) {\n        alert('Darn!');\n    }\n});\n```\n\nBecomes\n\n```javascript\nvar model = new Model({ id: 1 });\n\nmodel.fetch().done(function(result) {\n    alert('Yay!');\n}).fail(function(error) {\n    alert('Darn!');\n});\n```\nor\n```javascript\nvar model = new Model({ id: 1 });\n\nmodel.fetch().then(function(result) {\n    alert('Yay!');\n}, function(error) {\n    alert('Darn!');\n});\n```\n\n###Documentation\nBackbone.Deferred supports both the jQuery promise implementation and the Q promise implementation. I will use `.done` and `.fail` in the documentation but for Q these are one method, `.then(doneCallback, failCallback)`. In order to be compliant across libaries the first parameter is an array which contains all the paramters passed to the Backbone callback.\n\n**Backbone.Deferred.Model.fetch(*options*)**\n* .done(result)\n    * result.model - instance of the model\n    * result.response - the response from the server\n    * result.options - the options passed to the function\n* .fail(error)\n    * error.model - instance of the model\n    * error.xhr - the jQXhr object\n    * error.options - the options passed to the function\n\n**Backbone.Deferred.Model.save(*key*, *val*, *options*)**\n* .done(result)\n    * result.model - instance of the model\n    * result.response - the response from the server\n    * result.options - the options passed to the function\n* .fail(error)\n    * error.model - instance of the model\n    * error.xhr - the jQXhr object\n    * error.options - the options passed to the function\n\n**Backbone.Deferred.Model.save(*attributes*, *options*)**\n* .done(result)\n    * result.model - instance of the model\n    * result.response - the response from the server\n    * result.options - the options passed to the function\n* .fail(error)\n    * error.model - instance of the model\n    * error.xhr - the jQXhr object\n    * error.options - the options passed to the function\n\n**Backbone.Deferred.Model.destroy(*options*)**\n* .done(result)\n    * result.model - instance of the model\n    * result.response - the response from the server\n    * result.options - the options passed to the function\n* .fail(error)\n    * error.model - instance of the model\n    * error.xhr - the jQXhr object\n    * error.options - the options passed to the function\n\n**Backbone.Deferred.Collection.fetch(*options*)**\n* .done(result)\n    * result.collection - instance of the collection\n    * result.response - the response from the server\n    * result.options - the options passed to the function\n* .fail(error)\n    * result.collection - instance of the collection\n    * result.xhr - the jQXhr object\n    * result.options - the options passed to the function\n\n###Requirements\n* Backbone\n* Underscore\n* jQuery\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farhea%2Fbackbone-deferred","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farhea%2Fbackbone-deferred","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farhea%2Fbackbone-deferred/lists"}