Skip to content

Instantly share code, notes, and snippets.

@grabcode
Last active August 29, 2015 14:11
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 grabcode/cf7ad2cc0301ca9f2544 to your computer and use it in GitHub Desktop.
Save grabcode/cf7ad2cc0301ca9f2544 to your computer and use it in GitHub Desktop.
Timing backbone fetch
root = exports ? this
# Overloading backbone fetch method
previousFetch = Backbone.Collection.prototype.fetch
root.Backbone.Collection.prototype.fetch = (options={})->
asyncUniqId = _.uniqueId 'time_'+@constructor.name+'_'
console.time asyncUniqId
previousSuccess = if options? then options.success else undefined
options = _.extend(options,
success: =>
previousSuccess.apply @, arguments if previousSuccess?
console.timeEnd asyncUniqId
)
previousFetch.apply @, [options]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment