2017-06-28 10:20:22 +02:00
|
|
|
'use strict';
|
|
|
|
|
2021-01-19 10:42:45 +01:00
|
|
|
const { EventEmitter } = require('events');
|
|
|
|
|
|
|
|
class EventStore extends EventEmitter {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.setMaxListeners(0);
|
|
|
|
this.events = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
store(event) {
|
|
|
|
this.events.push(event);
|
|
|
|
this.emit(event.type, event);
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2021-03-12 11:08:10 +01:00
|
|
|
batchStore(events) {
|
|
|
|
events.forEach(event => {
|
|
|
|
this.events.push(event);
|
|
|
|
this.emit(event.type, event);
|
|
|
|
});
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2021-01-19 10:42:45 +01:00
|
|
|
getEvents() {
|
|
|
|
return Promise.resolve(this.events);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 11:42:00 +01:00
|
|
|
module.exports = EventStore;
|