- Chaplin
Chaplin.Collection → Source
Chaplin.Collection
is an extension of Backbone.Collection
. Major additions are disposal for improved memory management and the inclusion of the pub/sub pattern via the Chaplin.EventBroker
mixin.
Methods
All Backbone.Collection
methods.
serialize()
Memory-saving model serialization. Maps models to their attributes recursively. Creates an object which delegates to the original attributes when a property needs to be overwritten.
dispose()
Announces to all associated views that the model is being disposed. Unbinds all the global event handlers and also removes all the event handlers on the Model
module. Removes internal attribute hashes and event handlers. If supported by the runtime, the Collection
is frozen to prevent any changes after disposal.
Usage
To make use of Chaplin’s automatic memory management, use subscribeEvent
instead of registering methods directly as pub/sub listeners. This forces the handler context so the handler might be removed again on model/collection disposal. It’s crucial to remove all references to model/collection methods to allow them to be garbage collected.