The addListener method is used for adding listener for certain event. A listener can only be added once for a specific event. Adding the same listener multiple times will have no effect and nothing will occur.
The addListenerMany method is used for adding multiple listeners for certain events. A listener can only be added once for a specific event. Adding the same listener multiple times will have no effect and nothing will occur.
The dispatch method is used for dispatching a event.
The dispatchMany method is used for dispatching multiple event.
The listenOnce method is used for adding listener for certain event that is trigged only once.
The removeListener method is used for removing listener for certain event. Removing unadded listener will have no effect and nothing will occur.
The removeListener method is used for removing multiple listeners for certain event. Removing unadded listener will have no effect and nothing will occur.
The subscribe method is used for adding listener for certain event. A listener can only be added once for a specific event. Adding the same listener multiple times will have no effect and nothing will occur.
The subscribeMany method is used for adding listener for multiple events. A listener can only be added once for a specific event. Adding the same listener multiple times will have no effect and nothing will occur.
The withGroup method returns new instance of IEventBus where all the events names will be prefixed with a given group. This useful for multitennat applications.
import { type IEventBus } from "@daiso-tech/core";
async function main(eventBus: IEventBus): Promise<void> {
const eventBusA = eventBus.withGroup("a");
await eventBusA.subscribe("add", (event) => {
// This will be logged
console.log("eventBusA:", event);
});
const eventBusB = eventBus.withGroup("b");
await eventBusB.subscribe("add", (event) => {
// This will never be logged
console.log("eventBusB:", event);
});
await eventBusA.dispatch({
type: "add",
a: 1,
b: 2
})
}
EventBus class can be derived from any IEventBusAdapter.