Realtime two-way data-binding of Backbone model and collection data to a webserver via Socket.io. Makes realtime, collaborative editing in Backbone applications (hopefully) much simpler.
Install the module:
npm install backbone-socketio.
Server-side event listeners are added by injecting the Socket.io module as a dependency:
var io = ;;// continue to do your normal socket.io stuff here
Install the client-side code using Bower:
bower install backbone-socketio
or by downloading the minified file and hosting it on your server or CDN.
Include the file:
And mix the event listeners in using
Cocktail, or manually with
var socket = iobackboneMixins = socketMyModel MyCollection;MyModel = BackboneModel;Cocktail;MyCollection = BackboneCollection;Cocktail;
var socket = iobackboneMixins = socketSocketModel = BackboneModelSocketCollection = BackboneCollectionMyModel MyCollection;MyModel = SocketModel;MyCollection = SocketCollection;
This will set up listeners on all the necessary change events on models and collections then publish those changes down to the server. The server will then broadcast those changes back out to all other clients connected to the same socket and update the data in their corresponding models and collections.
Handling any DOM manipulation necessary to reflect changes in your views is up to you.
In lieu of a formal styleguide, take care to maintain the existing coding
style. Add unit tests for any new or changed functionality. Lint and test your
code using Grunt.
grunt will run unit tests and
- Added minified version of client file with source map file
- Only a model's changed data is sent over socket rather than entire model's JSON
- Reorganized file structure
- Rewrote unit tests using Mocha
- Support for Backbone.Collection
- Minor bug fixes
Basic proof of concept. Full support for add and remove (collection) and change (model) events.
- Put server component on NPM
- Make client component work with Bower
- Account/room-specific events
- Server-side hooks to run custom code in response to change events
- Probably a lot of other things I can't remember right now
Copyright (c) 2013-2014 Josh Mock
Licensed under the MIT license.