Last active
December 17, 2015 13:59
-
-
Save suprememoocow/5621496 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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