Skip to content

Instantly share code, notes, and snippets.

@ignu
Created May 16, 2014 15:21
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 ignu/1aca1eef296dc2ca5918 to your computer and use it in GitHub Desktop.
Save ignu/1aca1eef296dc2ca5918 to your computer and use it in GitHub Desktop.
do (Backbone) ->
_sync = Backbone.sync
Backbone.sync = (method, entity, options = {}) ->
_.defaults options,
beforeSend: _.bind(methods.beforeSend, entity)
complete: _.bind(methods.complete, entity)
sync = _sync(method, entity, options)
if !entity._fetch and method is "read"
entity._fetch = sync
sync
methods =
beforeSend: ->
@trigger "sync:start", @
complete: ->
@trigger "sync:stop", @
App.commands.setHandler "when:fetched", (entities, callback) ->
throw new Error("Callback required") unless callback
xhrs = _.chain([entities]).flatten().pluck("_fetch").value()
$.when(xhrs...).done(callback)
App.request "when:fetched", [userCollection, otherCollection] ->
region.show(new UserView({collection: userCollection}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment