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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@manuelflorezw/rxjs-bus

v0.1.3

Published

A simple RxJS event bus

Readme

RxJS Command Bus

Un Command Bus ligero basado en RxJS y TypeScript, para manejar comandos de manera tipada, asíncrona y desacoplada en aplicaciones frontend o backend.

Este bus permite:

  • Registrar handlers para tipos de comando específicos.
  • Emitir comandos de manera segura y tipada.
  • Soportar handlers síncronos o asíncronos (promesas u observables).
  • Limpiar suscripciones y desregistrar handlers dinámicamente.

Ideal para arquitecturas CQRS, patrones de comando/acción y sistemas basados en eventos.


Instalación

npm install rxjs-bus
# o con Yarn
yarn add rxjs-bus

Uso basico

  1. Definir un Registry de comandos El Registry define todos los tipos de comandos y los payloads esperados:
import { CommandBus } from 'rxjs-bus'

interface AppCommands {
  CREATE_USER: { name: string; email: string }
  DELETE_USER: { userId: string }
}

const bus = new CommandBus<AppCommands>()
  1. Definir un handler de comando Un handler debe implementar la interfaz CommandHandler y definir un método execute:
const createUserHandler = {
  execute: async (command: { type: "CREATE_USER"; payload: { name: string; email: string } }) => {
    console.log(`Creando usuario ${command.payload.name}`)
    // lógica de creación...
  }
}
  1. Registrar un handler
bus.register("CREATE_USER", createUserHandler)

Si intentas registrar otro handler para el mismo tipo, se lanzará un error:

bus.register("CREATE_USER", createUserHandler) // ❌ Error
  1. Emitir un comando
bus.emit({ type: "CREATE_USER", payload: { name: "Manuel", email: "[email protected]" } })

El handler registrado para CREATE_USER recibirá el comando y se ejecutará.

Manejo de errores

Actualmente los errores en handlers se silencian para que no rompan el flujo:

mergeMap((cmd) => from(handler.execute(cmd)).pipe(catchError(() => EMPTY)))

Se recomienda loguear errores dentro del handler o extender el bus para manejar errores globalmente.

Desregistrar handlers y limpiar el bus

  • Desregistrar un handler específico:
bus.unregister("CREATE_USER")
  • Limpiar todos los handlers y suscripciones:
bus.clear()

Buenas prácticas

  1. Mantén un handler por comando para evitar conflictos.
  2. Usa payloads tipados para aprovechar la seguridad de TypeScript.

Ejemplo completo

interface AppCommands {
  CREATE_USER: { name: string; email: string };
  DELETE_USER: { userId: string };
}

const bus = new CommandBus<AppCommands>();

bus.register("CREATE_USER", {
  execute: async (cmd) => console.log(`Usuario creado: ${cmd.payload.name}`)
});

bus.register("DELETE_USER", {
  execute: async (cmd) => console.log(`Usuario eliminado: ${cmd.payload.userId}`)
});

bus.emit({ type: "CREATE_USER", payload: { name: "Ana", email: "[email protected]" } });
bus.emit({ type: "DELETE_USER", payload: { userId: "123" } });

// Limpiar al final
bus.clear();

Contribuir

Se aceptan pull requests para:

  • Mejorar documentación y ejemplos.
  • Soporte avanzado de errores y concurrencia.
  • Integración con librerías de testing y CI.