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

obs-bus

v1.0.5

Published

A simple message bus implementation

Readme

Observer pattern message bus

Motivation

Most of event driven libraries implement following pattern:

emitter.on("some_event", some_callback)

While it is certainly useful and solves coupling problem, there are still few issues with it. We have to explicitly introduce callbacks to an emitter object, thus coupling both together. Such pattern encourages to make huge objects with tons of event handlers that are hard to maintain.

obs-bus

This library offers different approach.

import MessageBus from "obs-bus"

// Initializing message bus
const mBus = new MessageBus()

class Subscriber{
    //Any subscriber must have update method.
    //Following parameters will be passed when update called:
    update(message, senderObject, messageBus){
        //process message
    }
}

// Subscribing an object to a message
mBus.subscribe({subscriber, message, channel}) 

//We can form a message as array where first item is 
//the name of the message and other items is data
const message1 = ['TEST', {/*some data*/}]

//We can just send a string without any data.
//It will be turned into ['HEY'] implicitly.
const message2 = 'HEY'


// Putting message on the bus
mBus.deliver(message1, senderObject, channel)

// Now if message1 is relevant to subscriber, then subscriber's update method will be called.

So, if we want obj1 and obj2 to communicate, we don't have to make one of them some kind of emitter and have the other share some callback explicitly. We just subscribe them to message bus and they talk to each other by sending messages.

Subscriptions

Subscribing

mBus.subscribe({subscriber, message: "message_type_as_string", channel: '55'})

message and channel are optional message can be any string or symbol, channel can be anything subscriber must have an update method that is called when relevant message is received, otherwise error will be thrown.

A subscriber can subscribe to all messages:

mBus.subscribe({subscriber})

// Subscriber can subscribe to certain type of messages

mBus.subscribe({subscriber, message: "message_type_as_string"})

Subscriber can subscribe to a message and a channel. Message will be delivered to the subscriber only when message type channel match.

mBus.subscribe({subscriber, message: "message_type_as_string", channel: '55'})

Subscriber can subscribe to a channel, thus any message sent over to channel '55' will be delivered to subscriber

mBus.subscribe({subscriber,  channel: '55'})

Channels

Channel can be anything: number, string, object, array or another sender.

Each sender represents its own channel. When messages are delivered and there are some objects subscribed to the sender of the message - the message will be delivered while channel not explicitly provided:

const obj1, obj2
mBus.subscribe({obj1,  channel: obj2})

mBus.deliver(some_message, obj2)
// obj1 will receive this message

Unsubscribing

We can unsubscribe objects completely, no more messages will be delivered to this obj:

mBus.unsubscribe(obj)

We can unsubscribe from message or channel:

mBus.unsubscribe(obj, {message: "message_type"})
mBus.unsubscribe(obj, {channel})