mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 09:03:12 +03:00
25 lines
410 B
Markdown
25 lines
410 B
Markdown
|
# Domain Events
|
||
|
|
||
|
## Usage
|
||
|
|
||
|
```js
|
||
|
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);
|
||
|
```
|