Created
August 6, 2014 13:03
-
-
Save hc2p/bf93436bcb5ac58b88d6 to your computer and use it in GitHub Desktop.
extended Collection.prototype.fetch, added before:add:all and add:all event before and after 'add' events
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
orgFetch = Backbone.Collection::fetch | |
Backbone.Collection::fetch = (options={}) -> | |
success = options.success | |
options.success = (collection, resp, options) -> | |
collection.trigger 'before:add:all', collection, resp, options | |
collection.each (model) -> | |
model.trigger('add', model, collection, options) | |
collection.trigger 'add:all', collection, resp, options | |
success(collection, resp, options) if success | |
options.silent = true | |
orgFetch.call(this, options) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment