back to home

mroderick / PubSubJS

Dependency free publish/subscribe for JavaScript

4,873 stars
461 forks
29 issues
JavaScriptHTML

AI Architecture Analysis

This repository is indexed by RepoMind. By analyzing mroderick/PubSubJS in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.

Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.

Source files are only loaded when you start an analysis to optimize performance.

Embed this Badge

Showcase RepoMind's analysis directly in your repository's README.

[![Analyzed by RepoMind](https://img.shields.io/badge/Analyzed%20by-RepoMind-4F46E5?style=for-the-badge)](https://repomind.in/repo/mroderick/PubSubJS)
Preview:Analyzed by RepoMind

Repository Overview (README excerpt)

Crawler view

PubSubJS is a topic-based publish/subscribe library written in JavaScript. PubSubJS has synchronisation decoupling, so topics are published asynchronously. This helps keep your program predictable as the originator of topics will not be blocked while consumers process them. For the adventurous, PubSubJS also supports synchronous topic publication. This can give a speedup in some environments (browsers, not all), but can also lead to some very difficult to reason about programs, where one topic triggers publication of another topic in the same execution chain. Single process PubSubJS is designed to be used within a **single process**, and is not a good candidate for multi-process applications (like Node.js – Cluster with many sub-processes). If your Node.js app is a single process app, you're good. If it is (or is going to be) a multi-process app, you're probably better off using redis Pub/Sub or similar Key features • Dependency free • synchronisation decoupling • ES3 compatible. PubSubJS should be able to run everywhere that can execute JavaScript. Browsers, servers, ebook readers, old phones, game consoles. • AMD / CommonJS module support • No modification of subscribers (jQuery custom events modify subscribers) • Easy to understand and use (thanks to synchronisation decoupling) • Small(ish), less than 1kb minified and gzipped Getting PubSubJS There are several ways of getting PubSubJS • Install via npm ( ) • Use it directly from a CDN • https://www.jsdelivr.com/package/npm/pubsub-js • https://cdnjs.com/libraries/pubsub-js • https://unpkg.com/pubsub-js • Download a tagged version from GitHub **Note: the last version of this library available via bower is v1.5.4** Examples First you have to import the module: Basic example Cancel specific subscription Cancel all subscriptions for a function Clear all subscriptions for a topic Clear all subscriptions Get Subscriptions Count Subscriptions Error Handling Hierarchical addressing Tips Use "constants" for topics and not string literals. PubSubJS uses strings as topics, and will happily try to deliver your topics with ANY topic. So, save yourself from frustrating debugging by letting the JavaScript engine complain when you make typos. Example of use of "constants" Example of use of "symbol constants" with ES6/7 syntax Immediate Exceptions for stack traces in developer tools As of version 1.3.2, you can force immediate exceptions (instead of delayed exceptions), which has the benefit of maintaining the stack trace when viewed in dev tools. This should be considered a development only option, as PubSubJS was designed to try to deliver your topics to all subscribers, even when some fail. Setting immediate exceptions in development is easy, just tell PubSubJS about it after it has been loaded. Contributing to PubSubJS Please see CONTRIBUTING.md More about Publish/Subscribe • The Many Faces of Publish/Subscribe (PDF) • Addy Osmani's mini book on Patterns • Publish / Subscribe Systems, A summary of 'The Many Faces of Publish / Subscribe' Versioning PubSubJS uses Semantic Versioning for predictable versioning. Changelog Please see https://github.com/mroderick/PubSubJS/releases License MIT: http://mrgnrdrck.mit-license.org Alternatives These are a few alternative projects that also implement topic based publish subscribe in JavaScript. • http://www.joezimjs.com/projects/publish-subscribe-jquery-plugin/ • http://amplifyjs.com/api/pubsub/ • http://radio.uxder.com/ — oriented towards 'channels', free of dependencies • https://github.com/pmelander/Subtopic - supports vanilla, underscore, jQuery and is even available in NuGet