Skip to content

migpalg/event-emitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@migpalg/event-emitter

This package provides a robust implementation of the event emitter pattern, allowing developers to create and manage custom events with ease.

🚀 Getting started

Install this package with your favorite package manager:

npm install @migpalg/event-emitter

With yarn

yarn add @migpalg/event-emitter

Then you can start using this package to create event emitters and listeners:

import { EventEmitter } from "@migpalg/event-emitter";

const eventEmitter = new EventEmitter();

eventEmitter.on("test-event", ({ name }) => {
  console.log(`called event with: ${name}`);
});

eventEmitter.emit("test-event", { name: "John" });

We highly recommend using this package with typescript to describe your own set of events

import { EventEmitter } from "@migpalg/event-emitter";

export type MyEventMap = {
  push: { target: string };
};

const emitter = new EventEmitter<MyEventMap>();

emitter.emit("push", { target: "hello world!" });