New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

PubSub

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

PubSub - npm Package Compare versions

Comparing version
3.2.5
to
3.2.6
+18
examples/angular_1.x_example/package.json
{
"name": "angular_1.x_example",
"version": "1.0.0",
"description": "PubSub usage example in Angular 1.x",
"main": "app.js",
"scripts": {
"start": "http-server -o"
},
"author": "George Raptis <georapbox@gmail.com> (georapbox.github.io)",
"license": "MIT",
"dependencies": {
"PubSub": "*",
"angular": "~1.6.5"
},
"devDependencies": {
"http-server": "~0.10.0"
}
}
# PubSub usage example in Angular 1.x
## Install dependencies
```sh
$ npm install
```
## Run Dev Server
```sh
$ npm start
```
+7
-2
# CHANGELOG
## v3.2.6
- Ensure that listeners registered on the same topic are invoked in the order they are added.
- Minor updates on documentation.
- Update angular_1.x_example.
## v3.2.5

@@ -83,3 +88,3 @@ - Add working example using Angular 1.x.

- Correct annotations and provide examples.
- Update dev dependancies.
- Provide `npm` scripts to run the tasks. No more need for global dependancies installed (Grunt).
- Update devDependencies.
- Provide `npm` scripts to run the tasks. No more need for global dependencies installed (Grunt).

@@ -5,3 +5,3 @@ /**

*
* @version 3.2.5
* @version 3.2.6
* @author George Raptis <georapbox@gmail.com> (georapbox.github.io)

@@ -13,3 +13,3 @@ * @homepage https://github.com/georapbox/PubSub#readme

!function(a,b,c){"use strict";"function"==typeof define&&define.amd?define(c):"undefined"!=typeof module&&module.exports?module.exports=c():b.PubSub=c()}(0,this,function(){"use strict";function a(){var b,c,d;for(b=1,c=arguments.length;b<c;b++)for(d in arguments[b])Object.prototype.hasOwnProperty.call(arguments[b],d)&&(arguments[b][d]&&arguments[b][d].constructor&&arguments[b][d].constructor===Object?(arguments[0][d]=arguments[0][d]||{},a(arguments[0][d],arguments[b][d])):arguments[0][d]=arguments[b][d]);return arguments[0]}function b(a,b,c){var d;for(d in a)if(Object.prototype.hasOwnProperty.call(a,d)&&b&&!1===b.call(c,a[d],d,a))return;return a}function c(a){return function(){return this[a].apply(this,arguments)}}function d(a,b,c){for(var d,e,f=a._pubsub_topics,g=f[b],h=g?g.length:0;h;)h-=1,e=g[h].token,d=g[h],d.callback(c,{name:b,token:e}),!0===d.once&&a.unsubscribe(e)}function e(a,b,c,e){return!!a._pubsub_topics[b]&&(e?d(a,b,c):setTimeout(function(){d(a,b,c)},0),!0)}function f(){return this instanceof f?(this._pubsub_topics={},this._pubsub_uid=-1,this):new f}return f.prototype.subscribe=function(a,b,c){var d=this._pubsub_topics,e=this._pubsub_uid+=1,f={};if("function"!=typeof b)throw new TypeError("When subscribing for an event, a callback function must be defined.");return d[a]||(d[a]=[]),f.token=e,f.callback=b,f.once=!!c,d[a].push(f),e},f.prototype.subscribeOnce=function(a,b){return this.subscribe(a,b,!0)},f.prototype.publish=function(a,b){return e(this,a,b,!1)},f.prototype.publishSync=function(a,b){return e(this,a,b,!0)},f.prototype.unsubscribe=function(a){var b,c,d=this._pubsub_topics,e=!1;for(b in d)if(Object.prototype.hasOwnProperty.call(d,b)&&d[b]){for(c=d[b].length;c;){if(c-=1,d[b][c].token===a)return d[b].splice(c,1),a;b===a&&(d[b].splice(c,1),e=!0)}if(!0===e)return a}return!1},f.prototype.unsubscribeAll=function(){return b(this._pubsub_topics,function(a,b,c){c[b]=[]}),this},f.prototype.hasSubscribers=function(a){var c=this._pubsub_topics,d=!1;return null==a?(b(c,function(a){if(a.length>0)return d=!0,!1}),d):!!(Object.prototype.hasOwnProperty.call(c,a)&&c[a].length>0)},f.prototype.subscribers=function(){return a({},this._pubsub_topics)},f.prototype.subscribersByTopic=function(a){return this._pubsub_topics[a]?this._pubsub_topics[a].slice(0):[]},f.prototype.alias=function(a){return b(a,function(b,d){f.prototype[d]&&(f.prototype[a[d]]=c(d))}),this},f});
//# sourceMappingURL=pubsub.min.js.map
!function(t,n,r){"use strict";"function"==typeof define&&define.amd?define(r):"undefined"!=typeof module&&module.exports?module.exports=r():n.PubSub=r()}(0,this,function(){"use strict";function t(){var n,r,o;for(n=1,r=arguments.length;n<r;n++)for(o in arguments[n])Object.prototype.hasOwnProperty.call(arguments[n],o)&&(arguments[n][o]&&arguments[n][o].constructor&&arguments[n][o].constructor===Object?(arguments[0][o]=arguments[0][o]||{},t(arguments[0][o],arguments[n][o])):arguments[0][o]=arguments[n][o]);return arguments[0]}function n(t,n,r){var o;for(o in t)if(Object.prototype.hasOwnProperty.call(t,o)&&n&&!1===n.call(r,t[o],o,t))return;return t}function r(t){return function(){return this[t].apply(this,arguments)}}function o(t,n,r){for(var o,u,e=t._pubsub_topics[n],i=0,s=e?e.length:0;i<s;i+=1)u=e[i].token,(o=e[i]).callback(r,{name:n,token:u}),!0===o.once&&t.unsubscribe(u)}function u(t,n,r,u){return!!t._pubsub_topics[n]&&(u?o(t,n,r):setTimeout(function(){o(t,n,r)},0),!0)}function e(){return this instanceof e?(this._pubsub_topics={},this._pubsub_uid=-1,this):new e}return e.prototype.subscribe=function(t,n,r){var o=this._pubsub_topics,u=this._pubsub_uid+=1,e={};if("function"!=typeof n)throw new TypeError("When subscribing for an event, a callback function must be defined.");return o[t]||(o[t]=[]),e.token=u,e.callback=n,e.once=!!r,o[t].push(e),u},e.prototype.subscribeOnce=function(t,n){return this.subscribe(t,n,!0)},e.prototype.publish=function(t,n){return u(this,t,n,!1)},e.prototype.publishSync=function(t,n){return u(this,t,n,!0)},e.prototype.unsubscribe=function(t){var n,r,o=this._pubsub_topics,u=!1;for(n in o)if(Object.prototype.hasOwnProperty.call(o,n)&&o[n]){for(r=o[n].length;r;){if(r-=1,o[n][r].token===t)return o[n].splice(r,1),t;n===t&&(o[n].splice(r,1),u=!0)}if(!0===u)return t}return!1},e.prototype.unsubscribeAll=function(){return n(this._pubsub_topics,function(t,n,r){r[n]=[]}),this},e.prototype.hasSubscribers=function(t){var r=this._pubsub_topics,o=!1;return null==t?(n(r,function(t){if(t.length>0)return o=!0,!1}),o):!!(Object.prototype.hasOwnProperty.call(r,t)&&r[t].length>0)},e.prototype.subscribers=function(){return t({},this._pubsub_topics)},e.prototype.subscribersByTopic=function(t){return this._pubsub_topics[t]?this._pubsub_topics[t].slice(0):[]},e.prototype.alias=function(t){return n(t,function(n,o){e.prototype[o]&&(e.prototype[t[o]]=r(o))}),this},e});
//# sourceMappingURL=pubsub.min.js.map

@@ -1,1 +0,1 @@

{"version":3,"sources":["../src/pubsub.js"],"names":["name","context","definition","define","amd","module","exports","this","extend","i","l","key","arguments","length","Object","prototype","hasOwnProperty","call","constructor","forOwn","obj","callback","thisArg","alias","fn","apply","deliverTopic","instance","topic","data","currentSubscriber","token","topics","_pubsub_topics","subscribers","len","once","unsubscribe","publish","sync","setTimeout","PubSub","_pubsub_uid","subscribe","TypeError","push","subscribeOnce","publishSync","prop","tf","splice","unsubscribeAll","topicValue","topicKey","hasSubscribers","subscribersByTopic","slice","aliasMap","value"],"mappings":";;;;;;;;;;;CAUC,SAAUA,EAAMC,EAASC,GACxB,YACsB,mBAAXC,SAAyBA,OAAOC,IACzCD,OAAOD,GACoB,mBAAXG,SAA0BA,OAAOC,QACjDD,OAAOC,QAAUJ,IAEjBD,EAAY,OAAIC,KAElB,EAAUK,KAAM,WAChB,YAEA,SAASC,KACP,GAAIC,GAAGC,EAAGC,CAEV,KAAKF,EAAI,EAAGC,EAAIE,UAAUC,OAAQJ,EAAIC,EAAGD,IACvC,IAAKE,IAAOC,WAAUH,GAChBK,OAAOC,UAAUC,eAAeC,KAAKL,UAAUH,GAAIE,KACjDC,UAAUH,GAAGE,IAAQC,UAAUH,GAAGE,GAAKO,aACvCN,UAAUH,GAAGE,GAAKO,cAAgBJ,QACpCF,UAAU,GAAGD,GAAOC,UAAU,GAAGD,OACjCH,EAAOI,UAAU,GAAGD,GAAMC,UAAUH,GAAGE,KAEvCC,UAAU,GAAGD,GAAOC,UAAUH,GAAGE,GAMzC,OAAOC,WAAU,GAGnB,QAASO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AM,OAqBvEf,EAAO1B,UAAUQ,MAAQ,SAAUkC,GAOjC,MANAtC,GAAOsC,EAAU,SAAUC,EAAO/C,GAC5B8B,EAAO1B,UAAUJ,KACnB8B,EAAO1B,UAAU0C,EAAS9C,IAAQY,EAAMZ,MAIrCJ,MAGFkC","file":"pubsub.min.js"}
{"version":3,"sources":["../src/pubsub.js"],"names":["name","context","definition","define","amd","module","exports","this","extend","i","l","key","arguments","length","Object","prototype","hasOwnProperty","call","constructor","forOwn","obj","callback","thisArg","alias","fn","apply","deliverTopic","instance","topic","data","currentSubscriber","token","subscribers","_pubsub_topics","len","once","unsubscribe","publish","sync","setTimeout","PubSub","_pubsub_uid","subscribe","topics","TypeError","push","subscribeOnce","publishSync","prop","tf","splice","unsubscribeAll","topicValue","topicKey","hasSubscribers","subscribersByTopic","slice","aliasMap","value"],"mappings":";;;;;;;;;;;CAUC,SAAUA,EAAMC,EAASC,GACxB,aACsB,mBAAXC,QAAyBA,OAAOC,IACzCD,OAAOD,GACoB,oBAAXG,QAA0BA,OAAOC,QACjDD,OAAOC,QAAUJ,IAEjBD,EAAY,OAAIC,KAElB,EAAUK,KAAM,WAChB,aAEA,SAASC,IACP,IAAIC,EAAGC,EAAGC,EAEV,IAAKF,EAAI,EAAGC,EAAIE,UAAUC,OAAQJ,EAAIC,EAAGD,IACvC,IAAKE,KAAOC,UAAUH,GAChBK,OAAOC,UAAUC,eAAeC,KAAKL,UAAUH,GAAIE,KACjDC,UAAUH,GAAGE,IAAQC,UAAUH,GAAGE,GAAKO,aACvCN,UAAUH,GAAGE,GAAKO,cAAgBJ,QACpCF,UAAU,GAAGD,GAAOC,UAAU,GAAGD,OACjCH,EAAOI,UAAU,GAAGD,GAAMC,UAAUH,GAAGE,KAEvCC,UAAU,GAAGD,GAAOC,UAAUH,GAAGE,IAMzC,OAAOC,UAAU,GAGnB,SAASO,EAAOC,EAAKC,EAAUC,GAC7B,IAAIX,EAEJ,IAAKA,KAAOS,EACV,GAAIN,OAAOC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C,GAC5B6B,EAAOzB,UAAUJ,KACnB6B,EAAOzB,UAAU0C,EAAS9C,IAAQY,EAAMZ,MAIrCJ,MAGFiC","file":"pubsub.min.js"}

@@ -24,1 +24,9 @@ * {

}
button:disabled {
cursor: not-allowed;
}
.invalid {
color: red;
}

@@ -20,2 +20,4 @@ (function () {

$scope.isCounterRegistered = true;
$scope.sendUsers = function () {

@@ -34,2 +36,3 @@ // publish 'USERS_SENT' event with some data

eventEmitter.unsubscribe(COUNTER_CHANGED);
$scope.isCounterRegistered = eventEmitter.hasSubscribers(COUNTER_CHANGED);
};

@@ -56,3 +59,2 @@ }]);

app.controller('ControllerC', ['$scope', 'eventEmitter', function ($scope, eventEmitter) {

@@ -59,0 +61,0 @@ eventEmitter.subscribe(USERS_SENT, function (data) {

@@ -13,4 +13,4 @@ <!DOCTYPE html>

<h2>ControllerA</h2>
<p>
Counter: {{counter || 0}} <button ng-click="unsubscribeCounter()">Unsubscribe</button>
<p ng-class="{invalid : !isCounterRegistered}">
Counter: {{counter || 0}} <button ng-disabled="!isCounterRegistered" ng-click="unsubscribeCounter()">Unsubscribe</button>
</p>

@@ -38,6 +38,6 @@ <button ng-click="sendUsers()">Send users data to ControllerC</button>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.js"></script>
<script src="../../src/pubsub.js"></script>
<script src="node_modules/angular/angular.min.js"></script>
<script src="node_modules/PubSub/dist/pubsub.min.js"></script>
<script src="app.js"></script>
</body>
</html>
{
"name": "PubSub",
"version": "3.2.5",
"version": "3.2.6",
"description": "Javascript implementation of the Publish/Subscribe pattern.",

@@ -5,0 +5,0 @@ "main": "src/pubsub.js",

+23
-14
# PubSub
Javascript implementation of the [Publish–Subscribe pattern](http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern).
Javascript implementation of the [Publish/Subscribe](http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern) pattern.

@@ -57,5 +57,7 @@ [![Build Status](https://travis-ci.org/georapbox/PubSub.svg?branch=master)](https://travis-ci.org/georapbox/PubSub)

### Methods
<a name="PubSub+subscribe"></a>
### pubSub.subscribe(topic, callback, [once]) ⇒ <code>number</code>
### .subscribe(topic, callback, [once]) ⇒ <code>number</code>
Subscribe to events of interest with a specific topic name and a

@@ -85,3 +87,3 @@ callback function, to be executed when the topic/event is observed.

### pubSub.subscribeOnce(topic, callback) ⇒ <code>number</code>
### .subscribeOnce(topic, callback) ⇒ <code>number</code>
Subscribe to events of interest setting a flag

@@ -108,4 +110,6 @@ indicating the event will be published only one time.

### pubSub.publish(topic, [data]) ⇒ <code>boolean</code>
Publishes a topic, passing the data to its subscribers.
### .publish(topic, [data]) ⇒ <code>boolean</code>
Publishes a topic **asynchronously**, passing the data to its subscribers.
Asynchronous publication helps in that the originator of the topics will not be blocked while consumers process them.
For synchronous topic publication check `publishSync`.

@@ -131,4 +135,4 @@ **Kind**: instance method of <code>[PubSub](#PubSub)</code>

### pubSub.publishSync(topic, [data]) ⇒ <code>boolean</code>
Publishes a topic synchronously, passing the data to its subscribers.
### .publishSync(topic, [data]) ⇒ <code>boolean</code>
Publishes a topic **synchronously**, passing the data to its subscribers.

@@ -154,3 +158,3 @@ **Kind**: instance method of <code>[PubSub](#PubSub)</code>

### pubSub.unsubscribe(topic) ⇒ <code>boolean</code> \| <code>string</code>
### .unsubscribe(topic) ⇒ <code>boolean</code> \| <code>string</code>
Unsubscribes from a specific topic, based on the topic name,

@@ -177,3 +181,3 @@ or based on a tokenized reference to the subscription.

### pubSub.unsubscribeAll() ⇒ <code>[PubSub](#PubSub)</code>
### .unsubscribeAll() ⇒ <code>[PubSub](#PubSub)</code>
Clears all subscriptions whatsoever.

@@ -193,3 +197,3 @@

### pubSub.hasSubscribers([topic]) ⇒ <code>boolean</code>
### .hasSubscribers([topic]) ⇒ <code>boolean</code>
Checks if there are subscribers for a specific topic.

@@ -218,3 +222,3 @@ If `topic` is not provided, checks if there is at least one subscriber.

### pubSub.subscribers() ⇒ <code>object</code>
### .subscribers() ⇒ <code>object</code>
Gets all the subscribers as a set of key value pairs that

@@ -239,3 +243,3 @@ represent the topic's name and the event listener(s) bound.

### pubSub.subscribersByTopic(topic) ⇒ <code>array</code>
### .subscribersByTopic(topic) ⇒ <code>array</code>
Gets subscribers for a specific topic.

@@ -270,3 +274,3 @@

### pubSub.alias(aliasMap) ⇒ <code>[PubSub](#PubSub)</code>
### .alias(aliasMap) ⇒ <code>[PubSub](#PubSub)</code>
Creates aliases for public methods.

@@ -294,3 +298,3 @@

## Minify
## Minify source code

@@ -310,4 +314,9 @@ ```sh

## More about Publish/Subscribe pattern
- [The Observer Pattern - Addy Osmani](https://addyosmani.com/resources/essentialjsdesignpatterns/book/#observerpatternjavascript)
- [Publish–Subscribe pattern - Wikipedia](http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern)
## License
[The MIT License (MIT)](https://georapbox.mit-license.org/@2014)

@@ -5,6 +5,6 @@ /**

*
* @version 3.2.5
* @version 3.2.6
* @author George Raptis <georapbox@gmail.com> (georapbox.github.io)
* @homepage https://github.com/georapbox/PubSub#readme
* @repository git+https://github.com/georapbox/PubSub.git
* @repository https://github.com/georapbox/PubSub.git
* @license MIT

@@ -65,11 +65,11 @@ */

function deliverTopic(instance, topic, data) {
var topics = instance._pubsub_topics,
subscribers = topics[topic],
len = subscribers ? subscribers.length : 0,
currentSubscriber, token;
var topics = instance._pubsub_topics;
var subscribers = topics[topic];
var i = 0;
var len = subscribers ? subscribers.length : 0;
var currentSubscriber, token;
while (len) {
len -= 1;
token = subscribers[len].token;
currentSubscriber = subscribers[len];
for (; i < len; i += 1) {
token = subscribers[i].token;
currentSubscriber = subscribers[i];

@@ -139,5 +139,5 @@ currentSubscriber.callback(data, {

PubSub.prototype.subscribe = function (topic, callback, once) {
var topics = this._pubsub_topics,
token = this._pubsub_uid += 1,
obj = {};
var topics = this._pubsub_topics;
var token = this._pubsub_uid += 1;
var obj = {};

@@ -184,3 +184,6 @@ if (typeof callback !== 'function') {

/**
* Publishes a topic, passing the data to its subscribers.
* Publishes a topic asynchronously, passing the data to its subscribers.
* Asynchronous publication helps in that the originator of the topics will
* not be blocked while consumers process them.
* For synchronous topic publication check `publishSync`.
*

@@ -241,5 +244,5 @@ * @memberof PubSub

PubSub.prototype.unsubscribe = function (topic) {
var topics = this._pubsub_topics,
tf = false,
prop, len;
var topics = this._pubsub_topics;
var tf = false;
var prop, len;

@@ -317,4 +320,4 @@ for (prop in topics) {

PubSub.prototype.hasSubscribers = function (topic) {
var topics = this._pubsub_topics,
hasSubscribers = false;
var topics = this._pubsub_topics;
var hasSubscribers = false;

@@ -321,0 +324,0 @@ // If no arguments passed

@@ -252,1 +252,27 @@ /* eslint-disable strict, no-unused-vars, no-use-before-define, new-cap */

});
// Listeners right order of invokation
describe('Ensure that listeners registered on the same topic are invoked in the order they are added', function () {
it('Should invoke every listener in the order that was added', function () {
var ps = new PubSub();
var arr = [];
function listener1() {
arr.push('A');
}
function listener2() {
arr.push('B');
}
function listener3() {
arr.push('C');
}
ps.subscribe('my_topic', listener1);
ps.subscribe('my_topic', listener2);
ps.subscribe('my_topic', listener3);
ps.publishSync('my_topic');
expect(arr).toEqual(['A', 'B', 'C']);
});
});

Sorry, the diff of this file is not supported yet