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

Develop #141

Closed 4lessandrodev closed 6 months ago

4lessandrodev commented 6 months ago

Updates

[1.22.0] - 2024-04-13

Features Added #134

Implementation Details:


// Example Usage
const context = Context.events();

const handler = (event) => console.log(event);

// Subscribing to events under different contexts
context.subscribe('Context-A:SIGNUP', handler);
context.subscribe('Context-B:SIGNUP', handler);
context.subscribe('Context-C:SIGNUP', handler);
context.subscribe('Context-B:NOTIFY', handler);
context.subscribe('Context-B:SEND-EMAIL', handler);

// Dispatching events to specific contexts
// Dispatches the SIGNUP event to Context-B
context.dispatchEvent('Context-B:SIGNUP');

// Dispatches the SIGNUP event to all contexts
context.dispatchEvent('*:SIGNUP');

// Dispatches all events to all contexts. Not recommended
context.dispatchEvent('*:*');

// Dispatches all events under Context-B
context.dispatchEvent('Context-B:*');