Skip to content
datapimp edited this page Jul 9, 2012 · 3 revisions

The CollectionManager is a single instance which acts as a gateway to the instances of Luca.Collection created in your app. The intention is to provide a central place for creating one, and only one instance of a given collection type.

You can use CollectionManager independently, or you will get one by default when you use a Luca.Application with the default configuration.

A CollectionManager has a name property which is 'primary' by default. If you call Luca.CollectionManager.get() it will return the CollectionManager named 'primary' or the first one ever created. Attempting to create an additional CollectionManager instance with a name that is already used, will throw an error.

Collection Class Naming

Your custom Luca.Collection classes get named like MyApp.collections.SampleCollection. Through some string magic "SampleCollection" will get turned into "sample_collection". If you try to call collectionManager.getOrCreate("sample_collection") it will attempt tp get a collection named "sample_collection", and if it fails, will create a new instance of MyApp.collections.SampleCollection. If you want to force your CollectionManager to look in a specific namespace, set a reference to MyApp.collections on Luca.Collection.namespace.

Initial Collections

The CollectionManager can be configured with an @initialCollections property, which is an array of names of collection classes, similar to "sample_collection", or actual references to Collection Classes. The CollectionManager will create instances of the collection for you, and call fetch on all of them.

Event Relaying

By default @relayEvents is set to true on the CollectionManager. This means that any event that is triggered by a collection that is managed by the collection manager will be bubbled up to the manager. This feature is used by the collectionEvents configuration API used by Luca.View, but can also be used in custom situations as well.

Clone this wiki locally