backbone.aio

Use socket.io as a Backbone data transport.


Keywords
backbone, socket, socket.io, websocket, client, browser
License
MIT
Install
bower install backbone.aio

Documentation

Backbone.aio

A super-simple plugin which replaces Backbone's default AJAX transport with Socket.io. It hooks into Backbone.ajax - not Backbone.sync - leaving the sync layer untouched for easier integration with other libraries.

Features

  • Drop-in replacement which doesn't necessitate any changes to your front-end code.
  • Simple, explicit push and pull behaviour.
  • ~2kb minified, even without compression.

Installation

bower install backbone.aio
npm install backbone.aio

Usage

Usable in both an AMD and non-AMD context. Once loaded into your runtime, you must first provide your socket.io socket instance:

var socket = io(window.location.origin);
Backbone.Aio.setSocket(socket);

Please see the code in /docs for an example of usage, including additional features suchs as .link().

What it does do

  • Transforms all Backbone AJAX requests into socket.io events and emits them from the client.
  • Channels server responses to client-side events through Backbone's event mechanisms.
  • Lets you invoke client-side methods by emitting server-side events using the link method.
  • Assumes that all Backbone model IDs are numerical (a caveat of only having the AJAX request URL to work with).

What it doesn't do

  • Provide any automatic synchronisation between server and client instances of Backbone models and collections. There is no requirement to use Backbone server-side.

What it will do (to-do)

  • Namespacing to allow you to use socket.io as a transport only for certain models.