Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


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.


npm install @arguiot/broadcast.js --save


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).


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


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.


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.


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

// Somewhere in your program

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

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


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








No packages published