PHPackages                             cubicmushroom/js-pub-sub - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cubicmushroom/js-pub-sub

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cubicmushroom/js-pub-sub
========================

Light weight JavaScript PubSub library including callback priority and cancelling

192[1 issues](https://github.com/cubicmushroom/PubSub/issues)JavaScript

Since Jan 20Pushed 13y ago2 watchersCompare

[ Source](https://github.com/cubicmushroom/PubSub)[ Packagist](https://packagist.org/packages/cubicmushroom/js-pub-sub)[ RSS](/packages/cubicmushroom-js-pub-sub/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PubSub
======

[](#pubsub)

Javascript PubSub library supporting priorities &amp; interruption using `return false`.

Simple Example
--------------

[](#simple-example)

To subscribe to a topic, simple use the CMPubSub.subscribe() method...

```
var callback = function(msg) {
    alert(msg);
};
CMPubSub.sub('topicName', callback);

```

**Note:** The topic does not need to be pre-defined. You can subscribe to it before CMPubSub is made aware of it.

And to publish to a topic...

```
var obj = {
    some: 'info'
};
CMPubSub.pub('topicName', obj, 1, 2, 'a', 'b');

```

In this example, the `callback` function will be called with the arguments `[1, 2, 'a', 'b']`. Within the callback, `this` will refer to the obj object

**Note:** Passing a primitive type variable (number or string) is not done by reference, so any changes to it will not be perpetuated after the callback. Non-primitive variables are passed by reference, therefore you can modify the object &amp; the changes will be perpetuated.

Passing Context (`this`)
------------------------

[](#passing-context-this)

In order to allow the setting of `this` within the subscriber callback, the callback argument for the `CMPubSub.sub()` method can include the context object to use. If needed this the callback argument becomes an array with 2 items... the 1st the callback function &amp; the second being the context object.

Prioritising Callbacks
----------------------

[](#prioritising-callbacks)

You can add a 3rd parameter to the `CMPubSub.sub()` call to set the priority of the callback. The priority needs to be a number, with 1 is the highest priority. The default priority, if none is provided, is 9.

Interrupting Publish
--------------------

[](#interrupting-publish)

And callback can interrupt the publishing process, &amp; get the `CMPubSub.pub()` method to return false, simply by returning `false`. This will prevent any subsequent callback from being called, &amp; provide feedback to the calling function that the process has been interrupted. If the publish is not interrupted, or if there are no subscribers, then the `CMPubSub.pub()`call will return `true`.

Roadmap
-------

[](#roadmap)

1. Add the ability to un-subscribe;
2. Add namespacing for topics (like jQuery does), to make it easier to un-subscribe from events;

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b156769d704438a2a9e79cd9f7b7a01c8a7b17a191b389469ae55de8f0c982a6?d=identicon)[ToG](/maintainers/ToG)

---

Top Contributors

[![toby-griffiths](https://avatars.githubusercontent.com/u/4817007?v=4)](https://github.com/toby-griffiths "toby-griffiths (5 commits)")

### Embed Badge

![Health badge](/badges/cubicmushroom-js-pub-sub/health.svg)

```
[![Health](https://phpackages.com/badges/cubicmushroom-js-pub-sub/health.svg)](https://phpackages.com/packages/cubicmushroom-js-pub-sub)
```

###  Alternatives

[lyquidity/xbrl

Classes that implement the XBRL 2.1, XDT, Formulas, Generics and XFI specifications

482.8k](/packages/lyquidity-xbrl)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
