Augmented.js Next Core - Model & Collection
- AbstractModel
- Parameters
- uriRoot
- schema
- validationMessages
- get
- set
- escape
- has
- matches
- unset
- clear
- toJSON
- fetch
- fetch
- save
- save
- destroy
- destroy
- url
- uri
- keys
- values
- parse
- clone
- isNew
- hasChanged
- changedAttributes
- previous
- previousAttributes
- supportsValidation
- isValid
- validate
- getValidationMessages
- sync
- reset
- isEmpty
- toString
- update
- AbstractCollection
- Parameters
- preinitialize
- preinitialize
- toJSON
- add
- addModels
- removeModels
- set
- reset
- push
- pop
- unshift
- shift
- slice
- get
- has
- at
- find
- filter
- where
- findWhere
- sort
- pluck
- fetch
- create
- parse
- clone
- modelId
- values
- keys
- entries
- supportsValidation
- isValid
- getValidationMessages
- validate
- sync
- save
- update
- remove
- sortByKey
- isEmpty
- size
- toString
- CollectionIterator
Extends AugmentedObject
AbstractModel
Supports:
- Validation and Schemas
- Security
attributes
options
(optional, default{}
)args
...any
uri root property
uriRoot
string Root of the URI
Schema property
schema
object The JSON schema from this model
Validation Message property
validationMessages
object The property holding validation message data
Get the attribute form the Model
attribute
Returns any The model attribute
Set a hash of model attributes on the object, firing "change"
. This is
the core primitive operation of a model, updating the data and notifying
anyone who needs to know about the change in state.
key
value
options
Escape the attribute data
attribute
Has an attribute in the Model
attribute
Returns bolean Returns true if exists
Special-cased proxy to underscore's matches
method.
attrs
Remove an attribute from the model, firing "change"
. unset
is a noop
if the attribute doesn't exist.
attr
options
Clear all attributes on the model, firing "change"
.
options
Transforms model to pure toJSON
Fetch the model from the server, merging the response with the model's local attributes. Any changed attributes will trigger a "change" event.
options
(optional, default{}
)
fetch - Fetches the model as a 'get'
options
Set a hash of model attributes, and sync the model to the server.
If the server returns an attributes hash that differs, the model's
state will be set
again.
key
val
options
(optional, default{}
)
save - Saves the model as a 'create'
options
Destroy this model on the server if it was already persisted.
Optimistically removes the model from its collection, if it has one.
If wait: true
is passed, waits for the server to respond before removal.
options
(optional, default{}
)
destroy - Deletes the model as a 'delete'
options
Default URL for the model's representation on the server -- use uri()
Meta
- deprecated: use uri
Default URI for the model's representation on the server -- if you're using restful methods, override this to change the endpoint that will be called.
Keys of the attributes in this Model
Values of the attributes in this Model
Converts a response into the hash of attributes to be set
on
the model. The default implementation is just to pass the response along.
resp
options
Create a new model with identical attributes to this one.
A model is new if it has never been saved to the server, and lacks an id.
Determine if the model has changed since the last "change"
event.
If you specify an attribute name, determine if that attribute has changed.
attr
Return an object containing all the attributes that have changed, or false if there are no changed attributes. Useful for determining what parts of a view need to be updated and/or what attributes need to be persisted to the server. Unset attributes will be set to undefined. You can also pass an attributes object to diff against the model, determining if there would be a change.
diff
Get the previous value of an attribute, recorded at the time the last
"change"
event was fired.
attr
Get all of the attributes of the model at the time of the previous
"change"
event.
supportsValidation - Returns True if this model supports validation
Returns boolean Returns True if this model supports validation
isValid - Returns True if this model is valid Runs two level validation, attribute-level then JSON Schema
options
(optional, default{}
)
Returns boolean Returns True if this model is valid
Validates the model
Returns array Returns array of messages from validation
Gets the validation messages only in an array
Returns array Returns array of messages from validation
Sync model data (Should override as needed)
method
model
options
reset - clear and rewrite the model with passed data
data
object The data to replace the model with (optional)
isEmpty - returns true is the model is empty
Returns boolean returns true is the model is empty
toString - returns the model data as a string
Returns string returns the model data as a string
update - Updates the model as a 'update'
options
Extends AugmentedObject
Abstract Augmented Collection
Supports:
- Validation and Schemas
- Security
models
options
(optional, default{}
)
Schema property
models
options
schema
object The JSON schema from this collection
Validation Message property
models
options
validationMessages
object The property holding validation message data
The JSON representation of a Collection is an array of the models" attributes.
Add a model, or list of models to the set. models
may be
Models or raw JavaScript objects to be converted to Models, or any
combination of the two.
models
options
(optional, default{}
)
Meta
- deprecated: call addModels
Add a model, or list of models to the set. models
may be
Models or raw JavaScript objects to be converted to Models, or any
combination of the two.
Returns Model Return the added (or merged) model (or models).
Remove a model, or a list of models from the set.
models
(optional, default[]
)options
(optional, default{}
)
Update a collection by set
-ing a new list of models, adding new ones,
removing models that are no longer present, and merging models that
already exist in the collection, as necessary. Similar to Model#set,
the core operation for updating the data contained by the collection.
models
options
(optional, default{}
)
When you have more items than you want to add or remove individually,
you can reset the entire set with a new list of models, without firing
any granular add
or remove
events. Fires reset
when finished.
Useful for bulk operations and optimizations.
models
options
Add a model to the end of the collection.
model
options
Remove a model from the end of the collection.
options
Add a model to the beginning of the collection.
model
options
Remove a model from the beginning of the collection.
options
Slice out a sub-array of models from the collection.
args
...any
Get a model from the set by id, cid, model object with id or cid properties, or an attributes object that is transformed through modelId.
obj
Returns true
if the model is in the collection.
obj
Get the model at the given index.
index
find the model that matches these properties
attrs
object properties to match
Returns Augmented.AbstractModel model that matched
filter the models that match these properties
attrs
object properties to match
Returns array models that matched
Return models with matching attributes. Useful for simple cases of filter
.
attrs
object properties to matchfirst
Returns (Model | array) models that matched
Return the first model with matching attributes. Useful for simple cases
of find
.
attrs
Force the collection to re-sort itself. You don"t need to call this under normal circumstances, as the set will maintain sort order as each item is added.
options
(optional, default{}
)
Pluck an attribute from each model in the collection.
attr
Fetch the collection
options
Create a new instance of a model in this collection. Add the model to the
collection immediately, unless wait: true
is passed, in which case we
wait for the server to agree.
model
options
parse converts a response into a list of models to be added to the collection. The default implementation is just to pass it through.
resp
options
Create a new collection with an identical list of models as this one.
Define how to uniquely identify models in the collection.
attrs
Get an iterator of all models in this collection.
Get an iterator of all model IDs in this collection.
Get an iterator of all [ID, model] tuples in this collection.
supportsValidation - Returns True if this collection supports validation
Returns boolean Returns True if this collection supports validation
isValid - Returns True if this collection is valid
Returns boolean Returns True if this collection is valid
getValidationMessages - Returns the validation messages
Returns array Returns the message is an array of objects.
Validates the collection
Returns array Returns array of message from validation
Collecion.sync
method
model
options
save - Saves the collection as a "create"
options
(optional, default{}
)
update - Updates the collection as an "update"
options
(optional, default{}
)
remove - Remove from the collection as a "delete"
options
(optional, default{}
)
sortByKey - Sorts the collection by a property key
key
object The key to sort by
isEmpty - returns true is the collection is empty
Returns boolean returns true is the collection is empty
size - returns the size of the collection
Returns number returns the size of the collection
toString - returns the collection data as a string
Returns string returns the collection data as a string
A CollectionIterator implements JavaScript's Iterator protocol, allowing the
use of for of
loops in modern browsers and interoperation between
Collection and other JavaScript functions and third-party libraries
which can operate on Iterables.
collection
kind
Next model in collection
Once exhausted, remove the reference to the collection so future
calls to the next method always return done.