Class: Wraith.Collection
Defined in: | src/collection.coffee |
Inherits: | Wraith.Base |
Overview
The Collection object is a collection of Wraith.Model's that are accessed through Credit goes out to Alex MacCaw and his Spine framework for very obvious inspiration.
Instance Method Summary
- - (void) constructor(parent, as, klass) Constructor Sets up the parent, namespace (@as) and Wraith.Model class.
- - (Wraith.Model) create(attr) Bound Creates a new instance of the Wraith.Model belonging to this collection.
- - (Wraith.Model) add(item) Bound Adds the given instance of a Wraith.Model to the collection.
- - (Wraith.Model, Boolean) remove(id) Bound Removes a model from the collection, by ID (the _id attribute).
- - (Array<Wraith.Model>) all() Bound Returns all members of the collection as an array.
- - (Number) length() Bound Returns the length of the members array.
- - (Wraith.Model) findById(id) Bound Finds a given model within the collection by id (_id property)
- - (void) handleChange(key, value) Bound Acts as a wrapper for handling the change function coming from a model within the collection.
Inherited Method Summary
Methods inherited from Wraith.Base
#constructor, #bind, #unbind, #emit, #proxy
Constructor Details
- (void) constructor(parent, as, klass)
Sets up the parent, namespace (@as) and Wraith.Model class.
Instance Method Details
- (Wraith.Model) create(attr) (bound)
Creates a new instance of the Wraith.Model belonging to this collection.
- (Wraith.Model) add(item) (bound)
Adds the given instance of a Wraith.Model to the collection.
- (Wraith.Model, Boolean) remove(id) (bound)
Removes a model from the collection, by ID (the _id attribute).
- (Array<Wraith.Model>) all() (bound)
Returns all members of the collection as an array.
- (Number) length() (bound)
Returns the length of the members array.
- (Wraith.Model) findById(id) (bound)
Finds a given model within the collection by id (_id property)
- (void) handleChange(key, value) (bound)
Acts as a wrapper for handling the change function coming from a model within the collection. This emits a change event from the parent whenever a change happens on a model.