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

Mixu78/eventemitter

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published