Class: Wraith.Model
Defined in: | src/model.coffee |
Inherits: | Wraith.Base |
Overview
Our data model used throughout the application. Currently it is requred to do any data-binding or data-mapping in the views. Credit goes out to Alex MacCaw and his Spine framework for very obvious inspiration.
Class Method Summary
- + (void) field(name, opt) Sets up a field with the given name and options.
- + (void) hasMany(klass, as, opt) Sets up a collection given the Wraith.Collection object and options object.
Instance Method Summary
- - (void) constructor(attributes) Constructor Constructor
- - (void) reset(attributes) Perform a reset of the models attributes.
- - (Object, String, Boolean, Number) get(key) Bound Returns the value for the given key.
- - (void) set(key, val) Bound Sets the given attributes.key value to val.
- - (Boolean) isValid() Bound Checks to see if there are any errors on the models.
- - (Object) errors() Bound Returns an object with errors stored on it.
- - (Object) toJSON() Bound "Serializes" the model's attributes as JSON.
Inherited Method Summary
Methods inherited from Wraith.Base
#constructor, #bind, #unbind, #emit, #proxy
Class Method Details
+ (void) field(name, opt)
Sets up a field with the given name and options.
+ (void) hasMany(klass, as, opt)
Sets up a collection given the Wraith.Collection object and options object.
Constructor Details
- (void) constructor(attributes)
Constructor
Instance Method Details
- (void) reset(attributes)
Perform a reset of the models attributes. Will trigger "change" events on each property that is reset.
- (Object, String, Boolean, Number) get(key) (bound)
Returns the value for the given key. Will return undefined if not found on the attributes list.
- (void) set(key, val) (bound)
Sets the given attributes.key value to val. Warning: if the key is not found on attributes, it will throw an error.
@params [String] key The key of the attributes object to set. @params [Object, String, Boolean, Number] val The value to update the given key to.
- (Boolean) isValid() (bound)
Checks to see if there are any errors on the models. An error cache is stored privately so its as easy as checking if there is anything in that object.
- (Object) errors() (bound)
Returns an object with errors stored on it. Errors are stored with key as the attribute name and the value as the error.
- (Object) toJSON() (bound)
"Serializes" the model's attributes as JSON. (Really just returns the attributes object)