Skip to content

Instantly share code, notes, and snippets.

@suprememoocow
Last active December 17, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suprememoocow/5621496 to your computer and use it in GitHub Desktop.
Save suprememoocow/5621496 to your computer and use it in GitHub Desktop.
var fayeClient = new Faye.Client('/faye');
var LiveCollection = Backbone.Collection.extend({
constructor: function(models, options) {
Backbone.Collection.prototype.constructor.call(this, models, options);
this.subscription = fayeClient.subscribe(this.url, this._fayeEvent, this);
},
_fayeEvent: function(message) {
var method = message.method;
var body = message.body;
switch(method) {
case 'POST':
this._createEvent(body);
break;
case 'PUT':
this._updateEvent(body);
break;
case 'DELETE':
this._removeEvent(body);
break;
default:
...
}
},
...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment