Created
July 25, 2013 00:59
-
-
Save juliocesar/6075975 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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