Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Created July 25, 2013 00:59
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 juliocesar/6075975 to your computer and use it in GitHub Desktop.
Save juliocesar/6075975 to your computer and use it in GitHub Desktop.
# Multiple models/collections event tracking
# ==========================================
#
# This is handy, for instance, when something needs to happen once a set
# of collections fire `sync`. For example:
#
# Backbone.Events.when [User, Projects], 'sync', ->
# alert 'carry on with all the data ready'
Backbone.Events.when = (models, track, callback) ->
done = []
_.each models, (model) ->
model.once track, ->
done = _.union done, [model]
callback() if _.isEmpty _.difference(models, done)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment