Fire and listen to events in JavaScript.
Create, listen for, and fire custom events with a minimal JavaScript API.
import create from "evented-ts";
const evented = create();
evented.on("hello", (event) => console.log(event.args));
evented.fire("hello", "world");
Live events
Fire an event and watch a listener receive its payload.
hello listener
waitingNothing received yet.
Install
Install evented-ts with the package manager of your choice.
npm i evented-ts
pnpm add evented-ts
yarn add evented-ts
API
evented-ts exposes a small runtime API for managing listeners.
create()
Creates an isolated event emitter with its own listener registry.
on(eventName, listener)
Registers a listener and returns a function that removes it.
fire(eventName, eventArgs?)
Fires an event and passes its name and optional arguments to each listener.
off(eventName, listener?)
Removes a specific listener, or all listeners for the event when no listener is supplied.
listensTo(eventName) and listeners(eventName)
Inspect whether an event has listeners and retrieve its listener array.