4lessandrodev / rich-domain

A lib to help you create a robust project based on domain driven-design (ddd) principles with typescript and zero dependencies.
https://www.npmjs.com/package/rich-domain
MIT License
122 stars 5 forks source link

120 change the way to dispatch domain event #121

Closed 4lessandrodev closed 7 months ago

4lessandrodev commented 7 months ago

120

[1.20.0-beta] - 2024-03-17

Changed

Details: Introduced a new method to create an event management instance for the aggregate. Improved event handling and organization, enhancing the overall performance and efficiency of event management. Enabled easier integration and usage of event management features in various applications.

/**
 * Create a new instance of the event management class
 * Pass the aggregate as a parameter
 * Return an event management instance for the aggregate
 */
const events = new Events(aggregate);

events.addEvent('eventName', (...args) => {
    console.log('executing event...');
    console.log(args);
});

await events.dispatchEvents();

// OR

events.dispatchEvent('eventName');