UNPKG

cqrs-eda

Version:

Lightweight CQRS and Event-Driven Architecture library using TypeScript decorators, handlers and typings. Perfect for scalable event-driven apps.

30 lines (29 loc) 934 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Observer = Observer; exports.getObserverRegistry = getObserverRegistry; // Registry mapping event names to arrays of observer class constructors const observerRegistry = new Map(); /** * Decorator to register a class as an Observer for a specific event. * Multiple observers can listen to the same event. * * @param eventName - The name of the event to observe. * @returns Class decorator function. */ function Observer(eventName) { return function (target) { if (!observerRegistry.has(eventName)) { observerRegistry.set(eventName, []); } observerRegistry.get(eventName).push(target); }; } /** * Retrieves the entire observer registry. * * @returns Map where keys are event names and values are arrays of observer constructors. */ function getObserverRegistry() { return observerRegistry; }