
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@odg/events
Advanced tools
Install in your project using this command
yarn add @odg/events
interface EventType {
"event1": number, // receive number
"userRegister": {
name: string,
age: number
} // receive object,
}
const eventBus = new EventEmitterBus<EventType>();
const callback = (eventMessage: string) => {
console.log(eventMessage);
};
eventBus.subscribe("event1", callback); // Subscribe before dispatch
eventBus.dispatch("event1", 1); // Send 1 to event1
eventBus.dispatch("userRegister", { name: "ODGodinho", age: 18 }); // Send object to userRegister
class Example {
public constructor(
private eventBus: EventEmitterBus<EventType>
) {
}
public example(){
// code ...
this.eventBus.dispatch("event1", 1);
// code ...
}
}
enum EventName {
Example = "Example",
}
import { type EventObjectType } from "@odg/events";
import { type EventName } from "../app/Enums";
export interface EventExampleParameters {
// anything params
}
export interface EventBaseInterface extends EventObjectType {
[EventName.Example]: EventExampleParameters;
}
// IF the above interface does not have all existing laws in the enum it will report an error
export type EventTypes<T extends Record<EventName, unknown> = EventBaseInterface> = T;
import {
EventBusInterface,
EventServiceProvider as EventServiceProviderBase,
type EventListener,
} from "@odg/events";
import {
Container,
inject, injectable,
} from "inversify";
import { type EventTypes } from "../../Interfaces/EventsInterface";
import { ContainerName, EventName } from "../Enums";
import { type HomeEventListeners } from "../Listeners/HomeEventListeners";
@injectable()
export class EventServiceProvider extends EventServiceProviderBase<EventTypes> {
@inject(ContainerName.EventBus)
protected bus!: EventBusInterface<Events>;
/**
* Listeners for events in the application.
*
* @protected
* @type {EventListener<EventTypes>}
* @memberof EventServiceProvider
*/
protected listeners: EventListener<EventTypes> = {
[EventName.Example]: [
{
listener: new HomeEventListeners(), // You can use inversify
options: {},
},
],
};
public async boot(): Promise<void> {
await super.boot();
}
public async shutdown(): Promise<void> {
await super.shutdown();
}
}
import { type EventListenerInterface } from "@odg/events";
import { LoggerInterface } from "@odg/log";
import { inject, injectable } from "inversify";
import { type EventExampleType, type EventTypes } from "../../Interfaces/EventsInterface";
import { ContainerName, type EventName } from "../Enums"; // If use inversify
import { PageFactoryType } from "../Factory/PageFactory";
@injectable()
export class HomeEventListeners implements EventListenerInterface<EventTypes, EventName.Example> {
@inject(ContainerName.Logger) // You can use constructor to inject
public log!: LoggerInterface;
public async handler({ page }: EventExampleType): Promise<void> {
await this.log.debug("HomeEventListeners is sended");
}
}
Copy .env.example to .env and add the values according to your needs.
First install dependencies with the following command
yarn install
# or
npm install
To build the project, you can use the following command
if you change files, you need to run
yarn buildandyarn startagain
yarn build && yarn start
# or
yarn dev
To Test execute this command
yarn test
# or
yarn test:watch
FAQs
Events Interface for Ioc
We found that @odg/events demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authoritiesโ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socketโs new workflow scanning support.