Skip to content

Instantly share code, notes, and snippets.

@polarblau
Created July 13, 2011 12:55
Show Gist options
  • Save polarblau/1080242 to your computer and use it in GitHub Desktop.
Save polarblau/1080242 to your computer and use it in GitHub Desktop.
Backbone base collection class
class BaseCollection extends Backbone.Collection
_expiresAfter: 15 # seconds
_lastFetched: null
isStale: ->
now = (new Date()).getTime()
!@_lastFetched? || now - @_lastFetched > (@_expiresAfter * 1000)
refresh: (models, options) ->
super(models, options)
@_lastFetched = (new Date()).getTime()
fetch: (options = {}) ->
callback = options.success
options.success =(model, resp) =>
@_lastFetched = (new Date()).getTime()
callback(model, resp) if callback?
super(options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment