npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ea-utilities/mediator

v1.0.0

Published

Utility for the Mediator Pattern Mediator is a versatile class designed to streamline event-driven, asynchronous programming. It enables you to easily register, unregister, and invoke subscriber methods, making it ideal for managing WebSockets, Ajax call

Readme

Mediator

Utility for the Mediator Pattern Mediator is a versatile class designed to streamline event-driven, asynchronous programming. It enables you to easily register, unregister, and invoke subscriber methods, making it ideal for managing WebSockets, Ajax calls, DOM events, or any other asynchronous operations. This class ensures your code remains maintainable and testable.

Why Use Mediator?

The primary use case for Mediator is to effortlessly bind elements to WebSocket callbacks. However, its applications extend far beyond that. You can utilize it as an event management system, to decouple ts functions, handle Ajax request callbacks, and more.

Dependencies

  1. @angular > 16

Usage

Events

  1. First create a class with required properties in constructor
  2. class have to extend from IRequest
  3. Decorate event using @Event(name), name will be used in future module registers
import { IRequest, Event } from '@ea-utilities/mediator';

@Event("UserSavedEvent")
export class UserSavedEvent implements IRequest {
  constructor(public userId: number) { }
}

Handlers

  1. Create class handler with custom logic
  2. class have to extends IRequestHandler<MyEvent>, where MyEvent is the class created previously
  3. Implement/Override handle method with custom login
import { IRequestHandler } from '@ea-utilities/mediator';

export class SendTextMessageWhenUserSavedHandler extends IRequestHandler<UserSavedEvent> {
  public override handle(event: UserSavedEvent): void | Promise<void> {
    console.log(`Sending message to user ${event.userId}`);
  }
}

Register

  1. Go to app.config.ts and add provideMediator(...args)
import { provideMediator } from '@ea-utilities/mediator';

provideMediator([
   {
      eventType: UserSavedEvent,
      handlers: [ SendTextMessageWhenUserSavedHandler ]
   }
   ])

Usage

  1. Configure events, handlers and register (Previous steps)
  2. Go to component and inject Mediator _mediator = inject(Mediator)
  3. use Mediator.dispatch(event) or Mediator.dispatchSync(event), where event is that extending IRequest
  4. Optionally you can send options: { onError: callback }, to capture errors and perform them

Example

// events.ts

import { provideMediator, IRequest, IRequestHandler, Event } from '@ea-utilities/mediator'

@Event("UserSavedEvent")
export class UserSavedEvent implements IRequest {
  constructor(public userId: number) { }
}

export class SendTextMessageWhenUserSavedHandler extends IRequestHandler<UserSavedEvent> {
  public override handle(event: UserSavedEvent): void | Promise<void> {
    console.log(`Sending message to user ${event.userId}`);
  }
}

export class InformAdminWhenUserSavedHandler extends IRequestHandler<UserSavedEvent> {
  public override handle(event: UserSavedEvent): void | Promise<void> {
    console.log(`Admin notified about user ${event.userId} changes`);
  }
}

export class UpdateExternalSystemWhenUserSavedHandler extends IRequestHandler<UserSavedEvent> {
  public override handle(event: UserSavedEvent): void | Promise<void> {
    console.log(`External sytem updated with userId ${event.userId} changes`);
  }
}

export class ErrorUserSavedHandler extends IRequestHandler<UserSavedEvent> {
  public override handle(event: UserSavedEvent): void | Promise<void> {
    throw Error('ErrorUserSavedHandler from ErrorUserSavedHandler');
  }
}
//app.config.ts

import { provideMediator } from '@ea-utilities/mediator'

export const appConfig: ApplicationConfig = {
  providers: [
    ...
    provideMediator([
      {
        eventType: UserSavedEvent,
        handlers: [
          SendTextMessageWhenUserSavedHandler,
          InformAdminWhenUserSavedHandler,
          UpdateExternalSystemWhenUserSavedHandler,
          ErrorUserSavedHandler
        ]
      }
    ])
  ]
};
//app.component.ts

import { Mediator } from '@ea-utilities/mediator'

export class AppComponent {

  mediator = inject(Mediator);

  saveUser() {
    //logic for saving user
    console.log('saving user');

    //then dispatch user saved
    const event = new UserSavedEvent(5);
    this.mediator.dispatch(event, {
      onError: (error, event1) => {
        console.error(error, event1);
      }
    });
  }
}