mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
913ad18b71
no issue With the increased usage of DomainEvents, it gets harder to build reliable tests without having to resort to timeouts. This utility method allows us to wait for all events to be processed before continuing with the test. This change should speed up tests and make them more reliable. It only adds extra code when running tests and shouldn't impact production. |
||
---|---|---|
.. | ||
lib | ||
test | ||
.eslintrc.js | ||
index.js | ||
package.json | ||
README.md |
Domain Events
Usage
const DomainEvents = require('@tryghost/domain-events');
class MyEvent {
constructor(message) {
this.timestamp = new Date();
this.data = {
message
};
}
}
DomainEvents.subscribe(MyEvent, function handler(event) {
console.log(event.data.message);
});
const event = new MyEvent('hello world');
DomainEvents.dispatch(event);