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

@stackra/ts-events

v0.2.0

Published

Laravel-style event dispatcher for TypeScript — pub/sub with wildcard listeners, subscribers, decorators, multiple drivers (memory, redis, null), and RxJS streaming.

Downloads

58

Readme




@stackra/ts-events

Laravel-style event dispatcher for TypeScript with multiple drivers, wildcard matching, priority listeners, decorators, subscribers, and RxJS streaming.

Installation

pnpm add @stackra/ts-events

Features

  • 🚀 Multi-driver dispatching: Memory, Redis, Null
  • 🎯 Wildcard event matching (user.*, **)
  • ⚡ Priority-based listener execution
  • 🔁 One-time listeners via once()
  • 🎭 @OnEvent and @Subscriber decorators
  • 📡 RxJS observable streaming via asObservable()
  • 🛑 Halt-on-first-response with until()
  • 🏗️ EventsModule.forRoot() with DI integration
  • ⚛️ React hooks: useEvents(), useEvent()
  • 🏷️ DI tokens: EVENT_CONFIG, EVENT_MANAGER
  • 📦 EventManager extends MultipleInstanceManager pattern
  • 🔇 NullDispatcher for testing

Usage

Module Registration

/**
 * |-------------------------------------------------------------------
 * | Register EventsModule in your root AppModule.
 * |-------------------------------------------------------------------
 */
import { Module } from '@stackra/ts-container';
import { EventsModule } from '@stackra/ts-events';

@Module({
  imports: [
    EventsModule.forRoot({
      default: 'memory',
      dispatchers: {
        memory: { driver: 'memory', wildcards: true },
        redis: { driver: 'redis', connection: 'events' },
        test: { driver: 'null' },
      },
    }),
  ],
})
export class AppModule {}

Dispatching Events

/**
 * |-------------------------------------------------------------------
 * | Inject EventManager and dispatch events from services.
 * |-------------------------------------------------------------------
 */
import { Injectable, Inject } from '@stackra/ts-container';
import { EventManager, EVENT_MANAGER } from '@stackra/ts-events';

@Injectable()
export class UserService {
  constructor(@Inject(EVENT_MANAGER) private events: EventManager) {}

  async createUser(name: string) {
    const user = { id: '1', name };
    this.events.dispatcher().dispatch('user.created', user);
    return user;
  }
}

Decorators

/**
 * |-------------------------------------------------------------------
 * | Use @OnEvent on subscriber methods for declarative listening.
 * |-------------------------------------------------------------------
 */
import { Subscriber, OnEvent } from '@stackra/ts-events';

@Subscriber()
class UserSubscriber {
  subscribe() {}

  @OnEvent('user.created', { priority: 10 })
  onUserCreated(payload: any) {
    console.log('User created:', payload);
  }

  @OnEvent('user.*', { once: true })
  onAnyUserEvent(event: string, payload: any) {
    console.log(`[${event}]`, payload);
  }
}

React Hooks

/**
 * |-------------------------------------------------------------------
 * | useEvents() returns the EventManager from DI context.
 * |-------------------------------------------------------------------
 */
import { useEvents, useEvent } from '@stackra/ts-events';

function Notifications() {
  const events = useEvents();

  useEvent('notification.received', (payload) => {
    console.log('New notification:', payload);
  });

  return <div>Listening for notifications...</div>;
}

API Reference

| Export | Type | Description | | -------------------------- | ---------- | ------------------------------------------------------ | | EventsModule | Module | DI module with forRoot() static method | | EventManager | Service | Multi-driver manager (extends MultipleInstanceManager) | | EventService | Service | High-level API wrapping a single dispatcher | | MemoryDispatcher | Dispatcher | In-memory event dispatcher with wildcard support | | RedisDispatcher | Dispatcher | Redis-backed cross-process dispatcher | | NullDispatcher | Dispatcher | No-op dispatcher for testing | | @OnEvent(event, opts?) | Decorator | Mark a method as an event listener | | @Subscriber() | Decorator | Mark a class as an event subscriber | | @Channel(name) | Decorator | Bind a subscriber to a specific dispatcher channel | | useEvents() | Hook | Access EventManager from React context | | useEvent(event, handler) | Hook | Subscribe to an event in a component | | EVENT_CONFIG | Token | DI token for raw config object | | EVENT_MANAGER | Token | DI token (useExisting alias to EventManager) | | EventPriority | Enum | Priority levels: LOW, NORMAL, HIGH, CRITICAL | | defineConfig() | Utility | Type-safe config helper |

License

MIT