Backbone.Conduit.QuickCollection.fill(...)
The Backbone.Conduit.QuickCollection
fill(...) method provides an alternative to set(...), allowing you to add data to a Collection. It
supports the exact same options as specified by Backbone.Collection.set.
Like the refill module, it is provided by default in Conduit.QuickCollection:
var collection = new Conduit.QuickCollection();
collection.fill(someLargeArray, options);
You can also mix the functionality into your own Collection subclass:
var MyCollection = Backbone.Collection.extend({ ... });
Conduit.fill.mixin(MyCollection);
collection.fill(someLargeArray, options);
Differences from Backbone.Collection.set(...)
Conduit.fill's behavior differs in some significant ways:
- fill(...) does not trigger individual add, remove, or change events. Instead, a single "fill" event will be triggered after all elements have been added.
- No data validation on Model instance creation
- No tracking of previous attributes (i.e. "undefined") within the Model instances
Also, note the following may reduce the effectiveness of Conduit.fill's optimizations:
- If the Model being used by the Collection provides a
defaults
hash, the performance improvements will be reduced - If you've overwritten the Backbone.Model Constructor, the performance improvements will be greatly reduced (overriding initialize(...) is, of course, just fine)