Closed 4lessandrodev closed 7 months ago
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.
import { TsEvents } from 'rich-domain';
/**
* 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 TsEvents(aggregate);
events.addEvent('eventName', (...args) => {
console.log(args);
});
// dispatch all events
await events.dispatchEvents();
// OR dispatch a specific event
events.dispatchEvent('eventName');
Implemented a new event handling mechanism using the Handler class. Example:
// implement extending to EventHandler
class Handler extends EventHandler<Product> {
constructor() {
super({ eventName: 'sample' });
};
dispatch(product: Product, params: [DEvent<Product>, any[]]): void | Promise<void> {
const model = product.toObject();
const [event, args] = params;
console.log(model);
console.log(event);
// custom params provided on call dispatchEvent
console.log(args);
}
}
const event = new Handler();
aggregate.addEvent(event);
// or
aggregate.addEvent('sample', (...args) => {
console.log(args);
})
aggregate.dispatchEvent('sample', { custom: 'params' });
Fixed an issue with the event dispatching mechanism. Notes This version introduces significant changes to the event handling system, enhancing the flexibility and usability of the Aggregate class.
Is your feature request related to a problem? Please describe.
Currently, triggering an event using the available feature requires the following syntax:
This syntax deviates from the native JavaScript event handling pattern, which can be confusing and less intuitive for developers.
Describe the solution you'd like
I would like to propose changing the event handling syntax to align with the native JavaScript event handling pattern. The proposed syntax would be as follows:
This change would make the event handling mechanism more familiar and consistent with the standard JavaScript practice, improving readability and developer experience.
Describe alternatives you've considered
No alternative solutions have been considered at this time.
Additional context
No additional context is currently available.