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

@bloqz/relay

v1.2.0

Published

A package for enabling inter-bloc communication using an event relay system.

Downloads

614

Readme

@bloqz/relay

The @bloqz/relay package provides a lightweight, RxJS-powered event bus for enabling communication between different parts of an application. It uses a flexible subscription model that supports both simple string patterns and advanced predicate functions, making it a powerful solution for decoupled architectures.

Core Concepts

  • Relay: An event bus that allows for emitting and listening to events.
  • Topics: Named channels for events (e.g., 'user', 'cart'), allowing for targeted communication.
  • Events: The data payload associated with a topic, which must have a type property.
  • Pattern Matching: A simple yet powerful syntax for subscribing to events based on their topic and type.

Installation

This package is part of the Bloqz monorepo. To use it, add it as a dependency in your package.json:

"dependencies": {
  "@bloqz/relay": "1.0.0"
}

Usage

Creating a Relay

The primary export of this package is the createRelay function.

import { createRelay } from '@bloqz/relay';

// Create a new relay instance
const appRelay = createRelay();

Emitting Events

You can emit an event to a specific topic using the emit method. The event payload must be an object with a type property.

appRelay.emit('user', { type: 'login', userId: '123' });
appRelay.emit('notifications', { type: 'new', message: 'Welcome!' });

Listening with String Patterns

You can listen for events using a string pattern with the on method. This is the most common way to subscribe. The method returns an unsubscribe function.

// Listen for login and logout events on the 'user' topic
const unsubscribe = appRelay.on('user.{login|logout}', (topic, event) => {
  console.log(`Received event '${event.type}' on topic '${topic}'`);
});

// To stop listening
unsubscribe();

Listening with a Predicate Function

For more complex scenarios, you can use a predicate function to filter events. The predicate receives the topic and event and should return true if the handler should be executed.

const unsubscribe = appRelay.on((topic, event) => {
  return topic === 'user' && event.type === 'login';
}, (topic, event) => {
  console.log('User logged in:', event);
});

Pattern Matching Syntax

The pattern matching syntax provides a concise way to subscribe to events:

| Pattern | Description | | ----------------------- | ----------------------------------------------------- | | * | Matches any topic and any event type. | | user | Matches any event on the user topic. | | user|cart | Matches any event on the user or cart topics. | | *.login | Matches login events on any topic. | | user.{login|logout} | Matches login or logout events on the user topic. |

Disposing the Relay

When a relay is no longer needed, you can dispose of it to complete the underlying event stream and unsubscribe all listeners.

appRelay.dispose();