tinky / EventEmitter
A minimal EventEmitter implementation using mitt.
Provides a familiar Node.js-style EventEmitter API while using the lightweight mitt library under the hood. This class is used internally by Tinky for handling input events.
const emitter = new EventEmitter();
// Register an event listener
emitter.on("data", (payload) => {
console.log("Received:", payload);
});
// Emit an event
emitter.emit("data", { key: "value" });
// Register a one-time listener
emitter.once("single", (payload) => {
console.log("Called only once:", payload);
});new EventEmitter():
EventEmitter
EventEmitter
emitter:
Emitter<Events>
The underlying mitt emitter instance.
emit(
event,data?):boolean
Emits an event with optional data payload.
string
The name of the event to emit.
unknown
Optional data payload to pass to the event handlers.
boolean
Always returns true indicating the event was emitted.
off(
event,fn):this
Removes an event listener for the specified event.
string
The name of the event to stop listening for.
Handler<unknown>
The handler function to remove.
this
This EventEmitter instance for chaining.
on(
event,fn):this
Registers an event listener for the specified event.
string
The name of the event to listen for.
Handler<unknown>
The handler function to call when the event is emitted.
this
This EventEmitter instance for chaining.
once(
event,fn):this
Registers a one-time event listener that automatically removes itself after being called once.
string
The name of the event to listen for.
Handler<unknown>
The handler function to call when the event is emitted.
this
This EventEmitter instance for chaining.