Reference Source
public class | source

DataRecord

Direct Subclass:

DataModel

DataRecord class.

Example:


	API:
		->constructor(arg_collection, arg_id, arg_attributes)

		->get_collection():DataCollection - get record collection.

		->get_type():string - get record type.
		->get_id():string - get record id.
		->get_id_field_name():string - get record id.
		->get_attributes():Immutable.Map - get record attributes.

		->set(arg_attribute_name, arg_attribute_value):boolean - set an attribute value.
		->get(arg_attribute_name):any - get an 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.

		->serialize():string - transform attributes map to a string.
		->deserialize(string):boolean - load attributes from a string.

		->fill(arg_datas):boolean - fill attributes with given datas.
		->clear():boolean - fill attributes with default datas.

Constructor Summary

Public Constructor
public

constructor(arg_data_collection: DataCollection, arg_id: string, arg_attributes: object | Immutable.Map): nothing

Data record class, contains one collection item attributes.

Member Summary

Public Members
public

Class type flag.

Private Members
private

Record attributes map.

private

Datas collection instance.

private

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.

Method Summary

Public Methods
public

Clear all attributes values with default values.

public

deserialize(arg_serialized: stirng): boolean

Transform attributes string to an object.

public

fill(-: arg_datas): boolean

Fill all attributes values with given datas.

public

get(arg_attribute_path: string | array): any | undefined

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(arg_attribute_path: string | array, arg_attribute_value: any): boolean

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 Methods
private

_check_attribute(arg_attribute_name: string, arg_attribute_value: any): boolean

Check attribute name and value against model schema.

private

_emit(arg_event: string, arg_datas: any): nothing

Emit on event.

Public Constructors

public constructor(arg_data_collection: DataCollection, arg_id: string, arg_attributes: object | Immutable.Map): nothing source

Data record class, contains one collection item attributes.

Params:

NameTypeAttributeDescription
arg_data_collection DataCollection

data collection: contains schema.

arg_id string

data id, unique in collection.

arg_attributes object | Immutable.Map

initial datas values.

Return:

nothing

Public Members

public is_data_record: boolean source

Class type flag.

Private Members

private _attributes: object source

Record attributes map.

private _collection: DataCollection source

Datas collection instance.

private _dirty_attributes: array source

Record dirty attributes names.

private _has_dirty_attributes: boolean source

Record has dirty attributes values flag.

private _id: string source

Record unique identifier.

private _id_field_name: string source

Record identifier field name.

private _is_new: boolean source

Record is a new created record flag.

private _previous_attributes: Map source

Record dirty attributes map.

Public Methods

public clear(): boolean source

Clear all attributes values with default values.

Return:

boolean

success.

public deserialize(arg_serialized: stirng): boolean source

Transform attributes string to an object.

Params:

NameTypeAttributeDescription
arg_serialized stirng

serialized attributes.

Return:

boolean

success.

public fill(-: arg_datas): boolean source

Fill all attributes values with given datas.

Params:

NameTypeAttributeDescription
- arg_datas

new attribute values.

Return:

boolean

success.

public get(arg_attribute_path: string | array): any | undefined source

Get an attribute value.

Params:

NameTypeAttributeDescription
arg_attribute_path string | array

attribute name or path.

Return:

any | undefined

public get_attributes(): Immutable.Map source

Get record attributes.

Return:

Immutable.Map

public get_attributes_object(): object source

Get record attributes.

Return:

object

public get_collection(): DataCollection source

Get record collection.

Return:

DataCollection

public get_fields_names(): array source

Get record fields names.

Return:

array

array of all schema fields names strings.

public get_id(): string source

Get record id.

Return:

string

public get_id_field_name(): string source

Get record id field name.

Return:

string

public get_model(): DataModel source

Get record model.

Return:

DataModel

public get_type(): string source

Get record type.

Return:

string

public reload(): Promise source

Reload record from collection store.

Return:

Promise

promise of success (boolean)

public remove(): Promise source

Delete record from collection store.

Return:

Promise

promise of success (boolean)

public rollback(): Promise source

Disguard all dirty attributes values.

Return:

Promise

promise of success (boolean)

public save(): Promise source

Save all attributes values to the collection store.

Return:

Promise

promise of success (boolean)

public serialize(): string source

Transform attributes to a string.

Return:

string

serialized attributes.

public set(arg_attribute_path: string | array, arg_attribute_value: any): boolean source

Set an attribute value.

Params:

NameTypeAttributeDescription
arg_attribute_path string | array

attribute name or path.

arg_attribute_value any

attribute value.

Return:

boolean

public set_attributes(arg_attributes: object | Immutable.Map): nothing source

Set record attributes and normalize with schema.

Params:

NameTypeAttributeDescription
arg_attributes object | Immutable.Map

attributes map.

Return:

nothing

public set_removed(): nothing source

Set record as removed.

Return:

nothing

Private Methods

private _check_attribute(arg_attribute_name: string, arg_attribute_value: any): boolean source

Check attribute name and value against model schema.

Params:

NameTypeAttributeDescription
arg_attribute_name string

attribute name.

arg_attribute_value any

attribute value.

Return:

boolean

private _emit(arg_event: string, arg_datas: any): nothing source

Emit on event.

Params:

NameTypeAttributeDescription
arg_event string

event name.

arg_datas any

event datas (optional, default:undefined).

Return:

nothing