Create one object to store attributes. For performance reason, values of attributes passed to constructor
will not be cloned to attributes
property. So it means that value of attributes
property in this object
is just a reference to arguments attributes
passed to constructor.
Readonly
eventsReturn an object containing all the attributes that have changed. 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.
Optional
diff: Partial<T>Create a new model with identical attributes to this one.
Gets the value of an attribute.
For strongly-typed access to attributes, use the get
method privately in public getter properties.
The attribute key to retrieve.
The attribute value or undefined if not set.
Determine if the model has changed since the last "change"
event.
If you specify an attribute name, determine if that attribute has changed.
Optional
key: AcCmStringKey<T>Sets one or more attributes on the object.
For strongly-typed assignment of attributes, use the set
method privately in public setter properties.
Triggers change events unless the silent
option is specified.
The attribute key or an object of key-value pairs.
Optional
val: T[A]The value to set or options when key is an object.
Optional
options: AcCmObjectOptionsOptions for the set operation.
The current instance for method chaining.
// Set a single attribute
obj.set('name', 'MyEntity')
// Set multiple attributes
obj.set({ name: 'MyEntity', visible: true })
// Set with options
obj.set('name', 'MyEntity', { silent: true })
// Unset an attribute
obj.set('name', undefined, { unset: true })
// For strongly-typed subclasses
set name(value: string) {
super.set("name", value)
}
Sets one or more attributes on the object.
For strongly-typed assignment of attributes, use the set
method privately in public setter properties.
Triggers change events unless the silent
option is specified.
The attribute key or an object of key-value pairs.
Optional
options: AcCmObjectOptionsOptions for the set operation.
The current instance for method chaining.
// Set a single attribute
obj.set('name', 'MyEntity')
// Set multiple attributes
obj.set({ name: 'MyEntity', visible: true })
// Set with options
obj.set('name', 'MyEntity', { silent: true })
// Unset an attribute
obj.set('name', undefined, { unset: true })
// For strongly-typed subclasses
set name(value: string) {
super.set("name", value)
}
This class is used to store attributes of one data model. It has the following benifits.
changed
property to store all of changed valuesActually implementation of this class is based on class Model in Backbone.js. However, Model class in Backbone is too heavy. So we implement it again based on source code of class Model in Backbone.js. Morever, we want to keep our library with less external dependencies and don't want to introduce depenedency on Backbone.js.