Constructor
new Entity(dataopt, validatoropt)
The entity class aims to ease the use of instances use in combination of commands pattern and Event Sourcing.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
any |
<optional> |
{} | The data to bind on |
validator |
Validator |
<optional> |
entityValidator | Entity validator which is responsible to answer yes or no to the question: isValid. |
- Source:
Extends
Methods
(static) _defineGettersSetters() → {void}
Define default getters and setters to exposed first level schema properties.
- Source:
Returns:
- Type
- void
(static) initConstructor()
Initialize the Entity with the
- Source:
buildSnapshot() → {EventSourcing}
Build a new entity snapœshot based on current entity data and reset events stack.
- Inherited From:
- Source:
Returns:
- Type
- EventSourcing
init(snapshotopt, eventsopt) → {EventSourcing}
Initializes the entity with the given snapshot and events stack.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
snapshot |
Object |
<optional> |
{} | |
events |
Array |
<optional> |
[] |
- Inherited From:
- Source:
Returns:
- Type
- EventSourcing
isValid() → {boolean}
Check whether the instance data is valid against schema.
- Source:
Returns:
- Type
- boolean
push(method, argsopt) → {EventSourcing}
Push a new event to the entity stack. œ
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
method |
String | The method to be called on replay |
||
args |
Array |
<optional> |
[] | Arguments to apply the function on |
- Inherited From:
- Source:
Returns:
- Type
- EventSourcing
replay() → {EventSourcing}
Replay the current events stack from entity snapshop.
- Inherited From:
- Source:
Returns:
- Type
- EventSourcing
setEvents(eventsopt) → {EventSourcing}
Set the events to the current entity.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
events |
Array |
<optional> |
[] |
- Inherited From:
- Source:
Returns:
- Type
- EventSourcing
setSnapshot(snapshotopt) → {EventSourcing}
Set the snapshot to the current entity.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
snapshot |
Object |
<optional> |
{} |
- Inherited From:
- Source:
Returns:
- Type
- EventSourcing