Created
April 28, 2012 05:43
-
-
Save halfbaked/2516351 to your computer and use it in GitHub Desktop.
Auto-update collection changes in backbone
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
class sp.collections.DogCollection extends Backbone.Collection | |
initialize: -> | |
@fetch() | |
setInterval(@fetchChanges, 15*1000) | |
model: sp.models.DogModel | |
url: '/dogs' | |
changesUrl: -> | |
u = @url | |
if @length > 0 then u += "?lastUpdated="+@lastUpdated() | |
u | |
fetchChanges: => | |
@fetch({add:true, merge:true, url: @changesUrl()}) | |
lastUpdated: -> | |
lastModelUpdated = @max (model) -> | |
new Date(model.get('lastUpdated')) | |
lastModelUpdated.get('lastUpdated') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment