Skip to main content
Home

@eser/events@4.0.43
Built and signed on GitHub Actions

Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score64%
Downloads23/wk
Published2 weeks ago (4.0.43)

📡 @eser/events

Type-safe event handling with a fluent API built on top of the DOM EventTarget.

Features

  • Fluent API: Chainable event registration with add() and remove()
  • Type-Safe Dispatch: Dispatch custom events with typed payloads
  • Global Registry: Pre-configured global event system for convenience
  • DOM Compatible: Built on standard EventTarget for familiar behavior

Quick Start

import * as events from "@eser/events";

// Register event listeners
events.registry
  .add("user:login", (e) => console.log("User logged in:", e.detail))
  .add("user:logout", () => console.log("User logged out"));

// Dispatch events with data
events.dispatcher.dispatch("user:login", { detail: { userId: 123 } });

// One-time listeners
events.registry.add("init", () => console.log("Initialized"), { once: true });

Custom Event Registry

import { Registry } from "@eser/events";

// Create an isolated event system
const myEvents = new Registry();

myEvents.add("data:update", (e) => {
  console.log("Data updated:", e.detail);
});

const dispatcher = myEvents.build();
dispatcher.dispatch("data:update", { detail: { id: 1, value: "new" } });

Removing Listeners

import { Registry } from "@eser/events";

const registry = new Registry();

const handler = (e: Event) => console.log(e);
registry.add("click", handler);
registry.remove("click", handler);

API Reference

Registry

Method Description
add(type, listener, options?) Add event listener (chainable)
remove(type, listener, options?) Remove event listener (chainable)
build() Create a Dispatcher from this registry

Dispatcher

Method Description
dispatch(type, eventInitDict?) Dispatch a custom event

Global Exports

Export Description
registry Pre-configured global Registry
dispatcher Pre-configured global Dispatcher
events Factory function for the global system

🔗 For further details, visit the eserstack repository.

Built and signed on
GitHub Actions

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@eser/events

Import symbol

import * as events from "@eser/events";
or

Import directly with a jsr specifier

import * as events from "jsr:@eser/events";

Add Package

pnpm i jsr:@eser/events
or (using pnpm 10.8 or older)
pnpm dlx jsr add @eser/events

Import symbol

import * as events from "@eser/events";

Add Package

yarn add jsr:@eser/events
or (using Yarn 4.8 or older)
yarn dlx jsr add @eser/events

Import symbol

import * as events from "@eser/events";

Add Package

vlt install jsr:@eser/events

Import symbol

import * as events from "@eser/events";

Add Package

npx jsr add @eser/events

Import symbol

import * as events from "@eser/events";

Add Package

bunx jsr add @eser/events

Import symbol

import * as events from "@eser/events";