DataModel
Extends:
DataModel class.
Example:
API:
->constructor(arg_attributes)
->get_collection():DataCollection
->set(arg_attribute_name, arg_attribute_value):boolean - set an attribute value.
->get(arg_attribute_name):any - get an attribute value.
->get_id():string - get id attribute value.
->save():Promise - save all changed attributes to the collection store.
->rollback():boolean - disguard any unsaved changed attributes.
->remove():Promise - remove record from collection store.
->reload():Promise - restore attributes from collection store.
USAGE ON BROWSER:
class Cars extends DataModel {
constructor(arg_attributes) {
const ds = ... // get data store
super(ds.get_collection('cars'), undefined, arg_attributes)
}
}
var cars = new Cars( { engine:"fuel", color:"blue"} )
Constructor Summary
Public Constructor | ||
public |
constructor(arg_data_collection: DataCollection, arg_id: string | undefined, arg_attributes: object | Immutable.Map | undefined): nothing DataModel class inherits from DataRecord and aims to provide a high level API for sub-classes. |
Member Summary
Public Members | ||
public |
Class type flag. |
Inherited Summary
From class DataRecord | ||
public |
Class type flag. |
|
private |
Record attributes map. |
|
private |
Datas collection instance. |
|
private |
_dirty_attributes: array Record dirty attributes names. |
|
private |
Record has dirty attributes values flag. |
|
private |
Record unique identifier. |
|
private |
Record identifier field name. |
|
private |
Record is a new created record flag. |
|
private |
Record dirty attributes map. |
|
public |
Clear all attributes values with default values. |
|
public |
deserialize(arg_serialized: stirng): boolean Transform attributes string to an object. |
|
public |
Fill all attributes values with given datas. |
|
public |
Get an attribute value. |
|
public |
get_attributes(): Immutable.Map Get record attributes. |
|
public |
Get record attributes. |
|
public |
Get record collection. |
|
public |
get_fields_names(): array Get record fields names. |
|
public |
Get record id. |
|
public |
Get record id field name. |
|
public |
Get record model. |
|
public |
Get record type. |
|
public |
Reload record from collection store. |
|
public |
Delete record from collection store. |
|
public |
Disguard all dirty attributes values. |
|
public |
Save all attributes values to the collection store. |
|
public |
Transform attributes to a string. |
|
public |
Set an attribute value. |
|
public |
set_attributes(arg_attributes: object | Immutable.Map): nothing Set record attributes and normalize with schema. |
|
public |
set_removed(): nothing Set record as removed. |
|
private |
_check_attribute(arg_attribute_name: string, arg_attribute_value: any): boolean Check attribute name and value against model schema. |
|
private |
Emit on event. |
Public Constructors
public constructor(arg_data_collection: DataCollection, arg_id: string | undefined, arg_attributes: object | Immutable.Map | undefined): nothing source
DataModel class inherits from DataRecord and aims to provide a high level API for sub-classes.
Override:
DataRecord#constructorParams:
Name | Type | Attribute | Description |
arg_data_collection | DataCollection | data collection: contains schema (mandatory). |
|
arg_id | string | undefined | data id, unique in collection (optional). |
|
arg_attributes | object | Immutable.Map | undefined | initial datas values (optional). |
Return:
nothing |