Shorthand and complete type descriptor
Shorthand type descriptor
The shorthand is a pair of propertyName: Type
key/value like this:
Complete type descriptor
The complete descriptor allows you to declare additional info for the attribute. For Array types it's required to use the complete type descriptor because you must specify the itemType
.
default
The default of an attribute will be used if no value was provided for the specific attribute at construction time.
You can also use a function which receives the instance as a parameter in order to provide the default. The operation must be synchronous and the function will called after all the other attributes are already assigned, thus, you can use the other attributes of your class to compose a default value.
Please note that initializing an attribute with undefined will make it fallback to the default value while instantiating the structure, but it will not fallback when assigning the attribute after the structure is already constructed.
itemType
The itemType of an attribute is used to validate and coerce the type of each item from the attribute, like when the attribute type is Array
or some class that extends Array
.
Please refer to Validation in order to check a bit more on validation properties.
Type concept
Each attribute needs a type definition, that's how Structure validates and coerces the attribute's value. It can be divided into three categories (as in right now):
Primitives (Number, String, Boolean)
Classes (Date, Object, regular Classes and Structure classes as well)
Array/Array-like (Array, extended Array)
Last updated