{"id":18832796,"url":"https://github.com/ianhaggerty/backbone-sails","last_synced_at":"2025-12-18T02:50:41.454Z","repository":{"id":21018740,"uuid":"24311978","full_name":"ianhaggerty/backbone-sails","owner":"ianhaggerty","description":"A plugin for Backbone that makes integrating with Sails JS easier. Both leverage a model-view architecture, it's only natural to have them talk to each other.","archived":false,"fork":false,"pushed_at":"2024-03-08T18:55:30.000Z","size":1332,"stargazers_count":7,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-30T15:32:29.711Z","etag":null,"topics":["backbonejs","coffeescript","javascript","nodejs","pubsub","realtime","realtime-database","sailsjs","socket-io"],"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/ianhaggerty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2014-09-22T02:52:07.000Z","updated_at":"2024-03-08T14:48:18.000Z","dependencies_parsed_at":"2024-03-08T20:25:26.544Z","dependency_job_id":"13b4318e-5f6a-4bbc-95a7-963c493ee89a","html_url":"https://github.com/ianhaggerty/backbone-sails","commit_stats":null,"previous_names":["ianhaggerty/backbone-sails"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ianhaggerty/backbone-sails","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianhaggerty%2Fbackbone-sails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianhaggerty%2Fbackbone-sails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianhaggerty%2Fbackbone-sails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianhaggerty%2Fbackbone-sails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ianhaggerty","download_url":"https://codeload.github.com/ianhaggerty/backbone-sails/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianhaggerty%2Fbackbone-sails/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27789906,"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","status":"online","status_checked_at":"2025-12-18T02:00:09.725Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["backbonejs","coffeescript","javascript","nodejs","pubsub","realtime","realtime-database","sailsjs","socket-io"],"created_at":"2024-11-08T01:59:02.050Z","updated_at":"2025-12-18T02:50:41.435Z","avatar_url":"https://github.com/ianhaggerty.png","language":"JavaScript","readme":"Backbone.Sails\n==============\n\nBackbone.Sails is a plugin that aims to leverage to best of a [Sails](http://sailsjs.org/#/) backend within a [Backbone](http://backbonejs.org/#) frontend.\n\n#### Intro\n\nSails is a [nodejs](http://nodejs.org/) framework built on top of [express](http://expressjs.com/). It features fantastic support for [web sockets](https://developer.mozilla.org/en-US/docs/WebSockets), straight out of the box. As well as the extremely useful [CRUD](http://en.wikipedia.org/wiki/Create,_read,_update_and_delete) [blueprint](http://sailsjs.org/#/documentation/reference/blueprint-api) routes, which make [GET](http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods)'in, [POST](http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods)'in \u0026 [DELETE](http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods)'in a breeze. What's more, Sails supports these http 'verbs' through the client side web socket SDK [sails.io.js](https://github.com/balderdashy/sails.io.js). Allowing web developers to quickly build real-time applications that leverage the [resourceful pub/sub](http://sailsjs.org/#/documentation/reference/websockets/resourceful-pubsub) events.\n\nBackbone is an extremely popular and incredibly light weight javascript library that\n\n\u003e gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling\n\nIn a nut shell, Backbone gives structure to client side javascript for [single page applications](http://en.wikipedia.org/wiki/Single-page_application). However, Backbone was never built with sockets in mind. Those familiar will know the default `sync` method delegates to [`$.ajax`](http://api.jquery.com/jQuery.ajax/) which itself delegates to [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest). Furthermore, Backbone Model's and Collection's only fire purely clientside events - making it fiddly to respond to server side events on the client.\n\n#### This Plugin\n\nThis plugin attempts to bridge the gap between a [Backbone](http://backbonejs.org/#) frontend and a [Sails](http://sailsjs.org/#/) backend. It has it's own Model and Collection class which support syncing over sockets (delegating to [sails.io.js](https://github.com/balderdashy/sails.io.js) internally). Whats more, if the web socket isn't available, there are options to delegate to the original `sync` function.\n\nPerhaps more importantly, this plugin triggers the [resourceful pub/sub](http://sailsjs.org/#/documentation/reference/websockets/resourceful-pubsub) events on client side Model and Collection instances. This allows you to *respond to server side changes* on your models and collections, within the 'Backbone ecosystem'. This ultimately reduces development time, increases maintainability and can serve as a pillar of programming architecture for larger socket based applications.\n\n[Sails](http://sailsjs.org/#/) [blueprints](http://sailsjs.org/#/documentation/reference/blueprint-api) also features great support for [associations](http://sailsjs.org/#/documentation/concepts/ORM/Associations), [population](http://sailsjs.org/#/documentation/reference/blueprint-api/Populate.html) and [filter/sort criteria](http://sailsjs.org/#/documentation/reference/blueprint-api/Find.html). Backbone.Sails has built in functionality that helps streamline these powerful server side features into your Backbone workflow.\n\n#### A quick look at the API...\n\n```javascript\nvar Address;\nvar Person = Backbone.Sails.Model.extend({\n  modelName: \"person\",\n  assoc: {\n    address: function(){ return Address } // function returning address since circular dependence\n  },\n  config: {\n    populate: \"address\" // populate address by default (on fetch, save, etc)\n  }\n})\nvar PersonCollection = Backbone.Sails.Collection.extend({ model: Person })\n\nAddress = Backbone.Sails.Model.extend({\n  modelName: \"address\"\n  assoc: {\n    occupants: PersonCollection\n  }\n  config: {\n    populate: \"occupants\"\n  }\n})\n\nvar fred = new Person({ name: \"fred\", address: { street: \"maple grove\" } });\n\nfred.save(); // will create address and a person, address will be populated\n\naddressRaw = fred.get(\"address\"); // this will grab the raw data for address (a POJO)\naddress = fred.get(\"address\", true); // passing true will wrap the data with an Address constructor\naddress.set(\"number\", 4).save();\n\n// fetch is overloaded to call the 'populate' action, resolving with the address as a model\nfred.fetch(\"address\").done(function(address){\n  var jack = new Person({ name: \"jack\" })\n  address.addTo('occupants', jack) // will call the 'addTo' action, updating both the address and jack\n  .done(function(){\n    jack.isNew(); // false\n    address.get(\"occupants\", true).findWhere({ name:\"jack\" }); // truthy (since occupants populated)\n  })\n})\n\n// you can specify filter criteria like this\nvar persons = new PersonCollection();\npersons.query({\n  skip: 1,\n  limit: 1,\n  sort: \"name ASC\", // an object also works, e.g. { name: 1, street: -1 }\n  where: { name: { contains: \"a\" } }\n}).fetch()\n\n// unlike sails, populate can take filter criteria as well\naddress.populate({\n  occupants: {\n    limit: 2,\n    where: {\n      name: \"fred\"\n    }\n  }\n}).fetch()\n```\n\n#### Releases\n\nA [0.1](https://github.com/oscarhaggerty/Backbone.Sails/tree/master/releases/0.1) release is currently available. Sails v0.10 is *required* as well as io.sails v0.9.\n\n#### Dependencies\n\nBackbone.Sails depends on \n\n* [Sails v0.10](http://sailsjs.org/#/) `npm install sails@^0.10`\n* [Backbone](http://backbonejs.org/#)\n* [sails.io v0.9](https://github.com/balderdashy/sails.io.js)\n* [jQuery](http://jquery.com/)\n* [lodash](https://lodash.com/)\n\nThe server side blueprints **depend on lodash and bluebird**, so you'll need to run\n\n* `npm install bluebird --save`\n* `npm install lodash --save`\n\n#### Integration\n\n* **On The Client**\n  \n  Include `backbone.sails.js` after it's dependencies have been included. `Backbone.Sails` should be available thereafter.\n\n* **On The Server**\n  \n  Copy/paste the blueprints folder to `api/blueprints`. The blueprints are backwards compatible with the original sails blueprints.\n\n#### Configuration\n\nWhilst you are familiarizing yourself with the API, I suggest setting the following blueprint options within `config/blueprints.js`:\n\n* `mirror: true`\n  \n  `mirror` return's socket event's back to the client they originated from - **utterly crucial** for testing/learning and DRY'ing up your front end.\n  \n* `autowatch: true`\n  \n  `autowatch` is a flag to the `find` blueprint indicating to subscribe the client to `created` events. A good default is true, whilst your learning. (There is also a configuration option to dynamically flag this on or off from the client with Backbone.Sails)\n\n#### Documentation/Learning\n\nThe documentation currently available is:\n\n* [`Backbone.Sails.Model` reference](https://github.com/oscarhaggerty/Backbone.Sails/blob/master/docs/0.1/reference/Backbone.Sails.Model.md)\n* [`Backbone.Sails.Collection` reference](https://github.com/oscarhaggerty/Backbone.Sails/blob/master/docs/0.1/reference/Backbone.Sails.Collection.md)\n* [`Backbone.Sails` reference](https://github.com/oscarhaggerty/Backbone.Sails/blob/master/docs/0.1/reference/Backbone.Sails.md)\n* [Configuration reference](https://github.com/oscarhaggerty/Backbone.Sails/blob/master/docs/0.1/reference/Configuration.md)\n* [Populating Tutorial](https://github.com/oscarhaggerty/Backbone.Sails/blob/master/docs/0.1/tutorial/Populating.md)\n* [Syncing Tutorial](https://github.com/oscarhaggerty/Backbone.Sails/blob/master/docs/0.1/tutorial/Syncing.md)\n* [Adding And Removing Tutorial](https://github.com/oscarhaggerty/Backbone.Sails/blob/master/docs/0.1/tutorial/Adding%20%26%20Removing.md)\n\nThere is also an example chat client application that can be found [here](https://github.com/oscarhaggerty/Backbone.Sails/tree/master/assets/js/examples/apps/chatclient) that was developed with Backbone.Marionette in coffeescript.\n\nYou can also get a good idea of what Backbone.Sails is capable of by looking at the [test code](https://github.com/iahag001/Backbone.Sails/blob/master/assets/tests/backbone.sails.spec.coffee).\n\n## A Note from the Author\n\nThanks for your interest! Please see my [GitHub](https://github.com/ianhaggerty) or [Linkedin](https://www.linkedin.com/in/ihaggerty/) to stay updated.\n\n---\n\nThe MIT License (MIT)\n\nCopyright (c) 2022 Ian Haggerty\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fianhaggerty%2Fbackbone-sails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fianhaggerty%2Fbackbone-sails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fianhaggerty%2Fbackbone-sails/lists"}