2016-06-18 21:53:18 +02:00
|
|
|
'use strict';
|
|
|
|
const util = require('util');
|
|
|
|
const EventEmitter = require('events').EventEmitter;
|
2014-10-22 15:35:22 +02:00
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
function EventStore (eventDb) {
|
2016-05-01 22:53:09 +02:00
|
|
|
this.eventDb = eventDb;
|
2014-10-22 15:35:22 +02:00
|
|
|
EventEmitter.call(this);
|
|
|
|
}
|
2014-10-22 16:26:36 +02:00
|
|
|
util.inherits(EventStore, EventEmitter);
|
2014-10-22 15:35:22 +02:00
|
|
|
|
2014-10-23 10:32:13 +02:00
|
|
|
EventStore.prototype.create = function (event) {
|
2016-09-10 10:35:35 +02:00
|
|
|
return this.eventDb.store(event).then(() => this.emit(event.type, event));
|
2014-10-22 15:35:22 +02:00
|
|
|
};
|
|
|
|
|
2016-05-01 22:53:09 +02:00
|
|
|
module.exports = EventStore;
|