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

@dojo-ng/pubsub

v0.1.4

Published

Dojo NG publish/subscribe with namespaced topics, replay of the last value, and async iteration

Readme

@dojo-ng/pubsub

Publish and subscribe with namespaced topics. The bus keeps the last value of each topic, so a late subscriber starts with the current state.

Part of the Dojo NG framework packages: plain ESM, no Lit, and no runtime dependencies. BSD-3-Clause.

Install

npm install @dojo-ng/pubsub

Usage

import { createPubSub } from "@dojo-ng/pubsub";

const bus = createPubSub();

bus.publish("cart:count", 3);

// Late subscribers get the last value at once (replay is on by default).
bus.subscribe("cart:count", (count) => console.log("count", count));      // count 3

// A namespace subscriber hears every topic under it, with the real topic.
bus.subscribe("cart", (payload, topic) => console.log(topic, payload), { replay: false });

bus.publish("cart:total", 42);   // logs "cart:total 42"
bus.getLast("cart");             // 42, the newest value at or under "cart"

Subscribing

  • subscribe(topic, handler, options) returns a function that removes the subscription.
  • The handler receives the payload and the topic that was published.
  • Replay is on by default: a new subscriber receives the topic's last value at once. Pass { replay: false } when you only want new messages.
  • Every publish calls the handlers, even when the value is the same as before.
  • A handler that throws does not stop delivery to the others. The error is thrown again asynchronously, so it still reaches the console.

Namespaced topics

  • Topics nest on :. A publish to chat:room-1:typing reaches subscribers of chat:room-1:typing, then chat:room-1, then chat, most specific first.
  • Pass { separator: "/" } to createPubSub to use a different separator.
  • For a namespace topic, replay and getLast return the single newest value at or under that topic, not one value for each child topic.
  • Each message gets a sequence number (seq). One counter is shared by all topics in a bus, so messages can be ordered across topics.

Async iteration

subscribeAsync(topic, options) gives the same messages as an async iterable for for await.

const stop = new AbortController();

for await (const total of bus.subscribeAsync("cart:total", { signal: stop.signal })) {
  console.log("total is now", total);
  if (total > 100) break;        // break also ends the subscription
}
  • It starts listening when you call it, not when the loop starts, so no message in between is lost.
  • It does not replay the last value.
  • The subscription ends when the loop exits by break, return, or an error, or when the signal aborts.
  • If the loop is slower than the messages, up to 256 messages wait (DEFAULT_BUFFER_SIZE). After that, the oldest are dropped. Set bufferSize higher for a topic where losing an old message matters more than memory.

Using the bus as a store

bus.store is a ReadableStore: an object with getState() and subscribe(). It works with StoreController and the context keys from the Dojo NG components (@dojo-ng/store and @dojo-ng/context) with no adapter. The two packages share only this shape, not code, so neither depends on the other.

Learn more

The framework runtime guide shows the bus together with @dojo-ng/framework and @dojo-ng/websocket.

License

BSD-3-Clause. See LICENSE.