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

amplify-pubsub

v0.0.1

Published

pub/sub pattern implementation for in browser communication of components

Readme

amplify pubsub

The Amplify PubSub library provides three methods (amplify.publish, amplify.subscribe, and amplify.unsubscribe). Amplify provides methods to facilitate the Publish and Subscribe messaging pattern in your front-end application. The idea is that someone is broadcasting one or more messages (publishing) and someone else is listening to one or more messages (subscribing). By separating your logic out like this it allows for loose coupling of your components, which results in less brittle and more reusable code.

It is possible to implement the publish and subscribe model by using jQuery custom events, however, the AmplifyJS pub/sub component provides a slightly cleaner interface, prevents collisions between custom events and method names, and allows a priority to your messages.

Usage

amplify.subscribe( string topic, function callback ) amplify.subscribe( string topic, object context, function callback ) amplify.subscribe( string topic, function callback, number priority ) amplify.subscribe( string topic, object context, function callback, number priority )

Subscribe to a message.

  • topic: Name of the message to subscribe to.
  • [context]: What this will be when the callback is invoked.
  • callback: Function to invoke when the message is published.
  • [priority]: Priority relative to other subscriptions for the same message. Lower values have higher priority. Default is 10.

Returning false from a subscription will prevent any additional subscriptions from being invoked and will cause amplify.publish to return false.

Remove a subscription.

  • topic: The topic being unsubscribed from.
  • [context]: If provided, only subscriptions with a matching context will be unsubscribed.
  • callback: The callback that was originally subscribed.

Publish a message.

  • topic: The name of the message to publish.
  • Any additional parameters will be passed to the subscriptions.

amplify.publish returns a boolean indicating whether any subscriptions returned false. The return value is true if none of the subscriptions returned false, and false otherwise. Note that only one subscription can return false because doing so will prevent additional subscriptions from being invoked.

Examples

Subscribe and publish with no data

Subscribing to a topic with no data allows a generic message to be published on the bus for any event (user or code related) that needs communicated but no data is needed along with the event.

Subscribe and publish with data

The majority usage of a pub/sub system includes passing data from the publisher to any subscriptions listening to the topic.

You can choose to pass multiple parameters to any subscriber as well.

Subscribe and publish with context and data

Often there is a need to operate within a context for a subscription callback. It can be a reasonable strategy to have the context be set to a jQuery object that will be used inside of the subscription, or even a native DOM element.

Note: the following example assumes jQuery is already loaded on the page, and assumes at least one paragraph exists within the body of the page.

Subscribe to a topic with high priority

Subscribing to a topic with high priority can be useful as an error handler or anytime data may need to be checked or augmented before proceeding.

Amplify PubSub is part of what know as AmplifyJS a link