npm.io
3.3.6 • Published 3d ago

@tryghost/domain-events

Licence
MIT
Version
3.3.6
Deps
1
Size
6 kB
Vulns
0
Weekly
0
Stars
37

Domain Events

Purpose

Lightweight domain event bus for publishing and subscribing to application-level 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);