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

@lostpfg/puble

v0.2.15

Published

Puble provides a set of React hooks and a service for a publish-subscribe pattern implementation using RxJS

Downloads

22

Readme

Puble - PubSub React Hooks with RxJS

Puble provides a set of React hooks and a service for a publish-subscribe pattern powered by RxJS. It allows components within a React application to publish and subscribe to events asynchronously. Puble supports event priorities. Additionally it leverages the BroadCast Channel api to allow users to publish events between browsing contexts (windows, tabs, etc) and workers on the same origin.

Installation

npm install @lostpfg/puble

Components

EventPubSub Class A singleton class that manages topics and event handling. Allows for registering namespaces (topics), publishing events, subscribing to topics, and disposing of topics. Internaly it uses an interval of 50ms to extract chunks of events based on priority on each topic.

Methods:

  • registerNamespace(topic): Registers a new topic if not already present.
  • publish(topic, eventType, priority, priority?, payload?): Publishes a new event to a specific topic, with specific priority.
  • broadcast(topic, eventType, priority, priority?, payload?): Broadcasts a new event to a specific topic, with specific priority.
  • subscribeTopic(topic, options?): Subscribes to a topic. Optionally it retrieves historical events, filters out incoming values, throttles and debounces output.
  • subscribe(topic, eventType, options?): Subscribes to a topic and specific event types. Optionally it retrieves historical events, filters out incoming values, throttles and debounces output.
  • dispose(topic): Cleans up and removes a topic and its associated observables.
  • monitorEvents(): Monitoring info regarding the EventPubSub class.

Hooks

usePubSub

A hook for interacting with the EventPubSub. It provides methods to publish and subscribe to events within a React component.

Parameters:

  • topic: The topic name to subscribe to. Defaults to a wildcard that can be used for general purposes. Returns: An API with methods for publishing and subscribing to events, managing multiple subscriptions, and unsubscribing.

Example:

import React from "react";
import { useBroadcast } from "@lostpfg/puble";

const Broadcast: React.FunctionComponent = () => {
    const { publishMultiple, publish } = usePubSub();
    
    return (
        <React.Fragment>
            <button onClick={() => publish({ eventType: "test:event", priority: 5, payload: { timestamp: new Date().getTime() } })}>
                Publish Multiple
            </button>
            <button onClick={() => publishMultiple({ eventType: "test:event", priority: 1, payload: { timestamp: new Date().getTime() } }, { eventType: "test:event", priority: 10, payload: { timestamp: new Date().getTime() } })}>
                Publish Multiple
            </button>
        </React.Fragment>
    )
}

const Receiver: React.FunctionComponent = () => {
    const { subscribe } = usePubSub();
    const [event, setEvent] = React.useState<any>(null);

    React.useEffect(() => {
        const unsubscribe = subscribe("test:event", (event: any) => {
            setEvent(event);
        });

        return () => unsubscribe?.(); /* Optional as hook will handle it */
    }, []);

    return (
        <div>Last Event: {JSON.stringify(event)}</div>
    );
}

useBroadcast

Simplifies broadcasting events in React Components. It uses usePubSub to access broadcasting functionality.

Parameters:

  • topic: Optional topic name for the events. Returns:
  • Function to trigger events. It supports optional payload.

Example:


import React from "react";
import { useBroadcast } from "@lostpfg/puble";

const Example: React.FunctionComponent = () => {
    const broadcast = useBroadcast();
    
    return (
        <button onClick={() => broadcast("test:event", { priority: 5, payload: { timestamp: new Date().getTime() } })}>
            Broadcast
        </button>
    );
}

usePublisher

Simplifies publishing events in React Components. It uses usePubSub to access publishing functionality.

Parameters:

  • topic: Optional topic name for the events. Returns:
  • Function to trigger events. It supports optional payload.

Example:


import React from "react";
import { usePublisher } from "@lostpfg/puble";

const Example: React.FunctionComponent = () => {
    const publish = usePublisher();
    
    return (
        <button onClick={() => publish("test:event", { priority: 5, payload: { timestamp: new Date().getTime() } })}>
            Publish
        </button>
    );
}

useListener

Simplifies subscribtion to events in React Components. Automatically handles subscription lifecycle with component mounting and unmounting lifecycle.

Parameters:

  • Supports dual use: Either pass a topic name and event type, or just an event type for the default topic.
  • callback: Function that executes when an event is received.
  • deps: Dependency array to control re-subscription in React's useEffect.
import React from "react";
import { useListener } from "@lostpfg/puble";

const Receiver: React.FunctionComponent = () => {
    const [event, setEvent] = React.useState<any>(null);
    useListener("test:event", (event) => setEvent(event));

    return (
        <div>Last Event: {JSON.stringify(event)}</div>
    );
}

useMonitorData

Provides a simple to hook that subscribes to the monitor data of the core class. Automatically handles subscription lifecycle with component mounting and unmounting lifecycle.

Parameters:

  • Supports dual use: Either pass a topic name and event type, or just an event type for the default topic.
  • callback: Function that executes when an event is received.
  • deps: Dependency array to control re-subscription in React's useEffect.
import React from "react";
import { useMonitorData } from "@lostpfg/puble";

const Receiver: React.FunctionComponent = () => {
    const data = useMonitorData();

    return (
        <div>Monitoring Data: {JSON.stringify(data?? {})}</div>
    );
}