npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@odg/events

v1.1.0

Published

Events Interface for Ioc

Downloads

268

Readme

codecov Stargazers Made by ODGodinho Forks Repository size GitHub last commit License StyleCI

Table of Contents


🎇 Benefits

  • 🚀 Event Pattern for your project
  • 🚨 Over 800 rules for pattern, possible errors and errors in Linter
  • 🎇 Code quality guaranteed
  • 📢 Ioc Container
  • 🧪 100% Test Coverage

📗 Libraries

📁 Dependencies

⏩ Get Started


🔘 Use Event Interface

Install in your project using this command

yarn add @odg/events

📰 Usage

🌎 Implementation

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

🌎 Ioc

class Example {
    public constructor(
        private eventBus: EventEmitterBus<EventType>
    ) {
    }

    public example(){
        // code ...
        this.eventBus.dispatch("event1", 1);
        // code ...
    }
}

🏓 Use Event Provider

🚡 Enum Events Types

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;

🥮 Make a provider

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();
    }

}

🦻 Use Event Listeners

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");
    }

}

💻 Prepare To Develop

Copy .env.example to .env and add the values according to your needs.

📍 Start Project

First install dependencies with the following command

yarn install
# or
npm install

📨 Build and Run

To build the project, you can use the following command

if you change files, you need to run yarn build and yarn start again

yarn build && yarn start
# or
yarn dev

🧪 Teste Code

To Test execute this command

yarn test
# or
yarn test:watch