Sha256: ab0ab8d084a39d98d4fff21b3a44ab3030e4e1897487a463c6665c2f917a454a

Contents?: true

Size: 864 Bytes

Versions: 3

Compression:

Stored size: 864 Bytes

Contents

#= require ./base

class Ultimate.Backbone.Collection extends Backbone.Collection

  readyDeferred: null
  loaded: false
  loadedTimeStamp: null
  expireTime: Infinity

  constructor: (models, options = {}) ->
    @expireTime = options.expireTime  if options.expireTime?
    super

  reset: (models, options) ->
    @loadedTimeStamp = new Date()
    @loaded = true
    super

  ready: (callback, fetchOptions) ->
    lifeTime = if @loadedTimeStamp then (new Date() - @loadedTimeStamp) else 0
    if expired = lifeTime > @expireTime
      @readyDeferred = null
    if not @loaded or expired
      @readyDeferred ||= @fetch(fetchOptions)
      @readyDeferred.done =>
        callback.apply @
    else
      callback.apply @

  abort: ->
    if @readyDeferred?
      if @readyDeferred.state() is 'pending'
        @readyDeferred.abort()
        @readyDeferred = null

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ultimate-base-0.7.2 app/assets/javascripts/ultimate/backbone/collection.js.coffee
ultimate-base-0.6.2 app/assets/javascripts/ultimate/backbone/collection.js.coffee
ultimate-base-0.6.0 app/assets/javascripts/ultimate/backbone/collection.js.coffee