Halo
This library makes it quick and easy to build a real-time node backend for Backbone.js clients using Socket.io as the communication protocol.
Installation
npm install halo
Quick Start/Example
Back-end
First, require halo
var Halo = ;
Next, create a model by calling the extend method on Halo.model. You can give it an any properties and classProperties you'd like. You can also give it a constructor (called an initializer). If you override the default constructor of Halo.model, make sure to call the parent constructor using this.parent(Halo.Model).constructor somewhere in your function.
var MyModel = HaloModel;
Assign a collection to the new model class. Anytime this model is instantiated, that instance will be added to the collection you specify here.
MyModelcollection = contains: MyModel;
Next, create a View for this model. The View specifies how your model is represented to front-end clients and how those clients are permitted to interact with the model.
var MyModelView = HaloviewssocketModel;
To allow front-end clients to interact with the view, you must create a router and register the view with it.
var router = ;router;router;
Front-end
In your front-end app, include Socket.io and the Halo.sync.js Backbone extension using the following URLs. These URLs are automatically made available once router.listen() is invoked.
Now your Backbone models and collections can be bound to any Halo models or collection that have view objects registered with the Halo router.
var MyBackboneModel = BackboneModel;
For example, if you created a Backbone model that returned "MyModels" as the URL, which corresponds to the "name" property of the MyModelView, any time a client saved a change to a MyModel instance, that change will get pushed to all other clients who have a copy of that instance of MyModel. Similarly, creating new MyModels will add that new instance to any Backbone collection connected to MyModels.
Attribution/Credits
The code for Halo.sync was heavily borrowed from Backbone.ioBind, created by Jake Luer, and distributed under the MIT license. You can find his original library at http://alogicalparadox.com/backbone.iobind/ https://github.com/logicalparadox/backbone.iobind
License
Released under the MIT license. See file called LICENSE for more details.