Constructor
new EventSourcing(snapshotopt, eventsopt)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
snapshot |
Object |
<optional> |
{} | |
events |
Array |
<optional> |
[] |
- Source:
Example
class Person extends EventSourcing {
constructor(data = { name: 'unknown' }) {
super(data);
}
setName(name) {
this.push('setName', name);
this.data.name = name;
}
}
const alice = new Person();
alice.setName('Alice');
console.log(alice);
Methods
buildSnapshot() → {EventSourcing}
Build a new entity snapœshot based on current entity data and reset events stack.
- 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> |
[] |
- Source:
Returns:
- Type
- EventSourcing
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 |
- Source:
Returns:
- Type
- EventSourcing
replay() → {EventSourcing}
Replay the current events stack from entity snapshop.
- Source:
Returns:
- Type
- EventSourcing
setEvents(eventsopt) → {EventSourcing}
Set the events to the current entity.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
events |
Array |
<optional> |
[] |
- Source:
Returns:
- Type
- EventSourcing
setSnapshot(snapshotopt) → {EventSourcing}
Set the snapshot to the current entity.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
snapshot |
Object |
<optional> |
{} |
- Source:
Returns:
- Type
- EventSourcing