EntityStore
Constructor Summary
Public Constructor | ||
public |
constructor(models: Array) Constructs entity store |
Member Summary
Public Members | ||
public |
heap: {} Object with entities where key is [model name][entity id] and value is entity state |
|
public |
models: {} Object with models where key is model name and value is model instance |
|
public |
observables: {} Object with subjects where key is [model name][entity id] and value is entity state |
Private Members | ||
private |
_modelsArray: * Saved array of models for resetting purposes |
Method Summary
Public Methods | ||
public |
allEntities(model: string): Array Resolve all entities of model |
|
public |
clear() Clears heap and observables |
|
public |
deleteEntity(model: string, id: *) Delete entity from heap |
|
public |
entityUpdated(model: string, id: *, source: EntitySubject) Called when need to force update entity |
|
public |
getOrCreateEntitySubject(name: string, id: *): * Lazy EntitySubject evaluation |
|
public |
Put or replace state of entity |
|
public |
updateEntity(model: string, id: *, value: Object, source: EntitySubject, message: string) Notifies all subscribers entity is updated |
Private Methods | ||
private |
_createEntitySubject(model: string, id: *): * Create and return subject |
|
private |
_setupModelsAndHeap(models: *) Clears internal objects |
Public Constructors
Public Members
public heap: {} source
Object with entities where key is [model name][entity id] and value is entity state
public observables: {} source
Object with subjects where key is [model name][entity id] and value is entity state
Private Members
Public Methods
public allEntities(model: string): Array source
Resolve all entities of model
Params:
Name | Type | Attribute | Description |
model | string | name of model |
public deleteEntity(model: string, id: *) source
Delete entity from heap
Params:
Name | Type | Attribute | Description |
model | string | name of model |
|
id | * | entity id |
public entityUpdated(model: string, id: *, source: EntitySubject) source
Called when need to force update entity
Params:
Name | Type | Attribute | Description |
model | string | name of model |
|
id | * | entity id |
|
source | EntitySubject | cause of update |
public getOrCreateEntitySubject(name: string, id: *): * source
Lazy EntitySubject evaluation
Params:
Name | Type | Attribute | Description |
name | string | name of model |
|
id | * | entity id |
Return:
* |
See:
public updateEntity(model: string, id: *, value: Object, source: EntitySubject, message: string) source
Notifies all subscribers entity is updated
Params:
Name | Type | Attribute | Description |
model | string | name of model |
|
id | * | id of entity |
|
value | Object | result state |
|
source | EntitySubject | EntitySubject which caused update |
|
message | string | optional message for debugging purposes |
Private Methods
private _createEntitySubject(model: string, id: *): * source
Create and return subject
Params:
Name | Type | Attribute | Description |
model | string | name of model |
|
id | * | entity id |
Return:
* |
private _setupModelsAndHeap(models: *) source
Clears internal objects
Params:
Name | Type | Attribute | Description |
models | * | array of defined models |