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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@arguiot/broadcast.js

v1.0.4

Published

A simple notification dispatch mechanism that enables the broadcast of information to registered observers within your code.

Downloads

15

Readme

BroadcastJS

A simple notification dispatch mechanism that enables the broadcast of information to registered observers within your code.

What is BroadcastJS?

BroadcastJS is a tiny library for a notification dispatch mechanism that enables the broadcast of information to registered observers. Basically, it helps you escalate your data without caring about the context within your code. So, it enables you to send data to a different part of your program.

Install

npm install @arguiot/broadcast.js --save

Notification

A Notification is a container for information broadcast through a notification center to all registered observers.

A notification contains a name and an object. It is broadcast to by instances of NotificationCenter. The name is a tag identifying the notification. The object is any object that the poster of the notification wants to send to observers of that notification (typically, the data posted by the notification).

Structure

class Notification {
	constructor(name, object = null) {} // object is the data you want to share
}

NotificationCenter

The NotificationCenter is a huge part of BroadcastJS: it's the object that will help manage all your observers and contexts.

When an object adds itself as an observer, it specifies which notifications it should receive. An object may, therefore, call this method several times in order to register itself as an observer for several different notifications. Each running app has a default notification center, and you can create new notification centers to organize communications in particular contexts.

Please remember that a notification center can deliver notifications only within a single program, and cannot share data across windows or tabs.

Structure

class NotificationCenter {
	get default() {}
	addObserver(name, callback, reference = null) {} // reference helps referencing a specific observer that may listen to the same Notification.
	removeObserver(name, reference = null) {}
	post(notification) {}
}

The default NotificationCenter

The default getter helps you get a global instance of NotificationCenter, so you can share notifications within your entire web app.

If your web app uses notifications extensively, you may want to create and post to your own notification centers rather than posting only to the default notification center. When a notification is posted to a notification center, the notification center scans through the list of registered observers, which may slow down your web app. By organizing notifications functionally around one or more notification centers, less work is done each time a notification is posted, which can improve performance throughout your app.

Demo

const { Notification, NotificationCenter } = require("@arguiot/broadcast.js")


// Somewhere in your program

NotificationCenter.default.addObserver("test", data => {
	console.log(data.data) // will print "Message"
})

// Somewhere else
const msg = new Notification("test", {
	data: "Message"
})

NotificationCenter.default.post(msg)