@rbxts/eventemitter
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@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, item: Item) => 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");

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    3
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    3

Package Sidebar

Install

npm i @rbxts/eventemitter

Weekly Downloads

3

Version

1.0.0

License

ISC

Unpacked Size

11 kB

Total Files

6

Last publish

Collaborators

  • mixu_78