Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Latest commit

 

History

History
37 lines (28 loc) · 865 Bytes

README.md

File metadata and controls

37 lines (28 loc) · 865 Bytes

@rbxts/eventemitter

NPM

Node.js-inspired event emitter class. Also typesafe.

Installation

npm i @rbxts/eventemitter

Usage

First make an interface with eventName: listenerFunction pairs, for example

interface GameEvents {
	playerGotItem: (player: Player, item: Item) => void;
	playerDied: (player: Player) => void;
}

Then create the emitter like so:

const Emitter = new EventEmitter<GameEvents>();

where GameEvents is your event interface.

Example

import EventEmitter from "@rbxts/eventemitter";

interface Events {
	playerDead: (playerName: string) => void;
}

const Emitter = new EventEmitter<Events>();

Emitter.on("playerDead", (player) => print(`${player} died!`));

Emitter.emit("playerDead", "Mixu_78");