Comparing version 1.6.0 to 1.6.1
{ | ||
"name": "pubsub-js", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "Dependency free publish/subscribe library", | ||
@@ -12,2 +12,3 @@ "main": "./src/pubsub.js", | ||
"coverage": "nyc --reporter=lcov --reporter=text --reporter=json-summary npm test", | ||
"prepublishOnly": "jsdoc2md --template ./docs/template.hbs --files ./src/*.js > ./docs/docs.md", | ||
"lint": "eslint src/ test/", | ||
@@ -34,8 +35,9 @@ "test": "mocha" | ||
"devDependencies": { | ||
"eslint": "^4.14.0", | ||
"mocha": "^4.0.1", | ||
"nyc": "^11.4.1", | ||
"eslint": "4.19.1", | ||
"jsdoc-to-markdown": "^4.0.1", | ||
"mocha": "5.1.1", | ||
"nyc": "11.7.1", | ||
"referee": "^1.2.0", | ||
"sinon": "^4.1.3" | ||
"sinon": "5.0.3" | ||
} | ||
} |
@@ -1,6 +0,16 @@ | ||
# PubSubJS | ||
<div align="center"> | ||
<p> | ||
<h1> PubSubJS | ||
</p> | ||
[![Travis build status](https://img.shields.io/travis/mroderick/PubSubJS.svg)](https://travis-ci.org/mroderick/PubSubJS) [![David](https://img.shields.io/david/mroderick/pubsubjs.svg)](https://david-dm.org/mroderick/PubSubJS) [![David](https://img.shields.io/david/dev/mroderick/pubsubjs.svg)](https://david-dm.org/mroderick/PubSubJS#info=devDependencies&view=table) | ||
![npm version](https://img.shields.io/npm/v/pubsub-js.svg) ![npm license](https://img.shields.io/npm/l/pubsub-js.svg) ![npm downloads per month](https://img.shields.io/npm/dm/pubsub-js.svg) | ||
[![Coverage Status](https://coveralls.io/repos/github/mroderick/PubSubJS/badge.svg)](https://coveralls.io/github/mroderick/PubSubJS) | ||
<p> | ||
<a href="https://travis-ci.org/mroderick/PubSubJS"><img src="https://img.shields.io/travis/mroderick/PubSubJS.svg?style=flat-square" alt="Travis build status" title="Travis build status" /></a><!-- | ||
--><a href="https://david-dm.org/mroderick/PubSubJS"><img src="https://img.shields.io/david/mroderick/pubsubjs.svg?style=flat-square" alt="Dependencies" title="Powered by David" /></a><!-- | ||
--><a href="https://david-dm.org/mroderick/PubSubJS#info=devDependencies&view=table"><img src="https://img.shields.io/david/dev/mroderick/pubsubjs.svg?style=flat-square" alt="DevDependencies" title="Powered by David" /></a><!-- | ||
--><a href="https://www.npmjs.com/package/pubsub-js"><img src="https://img.shields.io/npm/v/pubsub-js.svg?style=flat-square" alt="NPM version" title="Click to go to NPM" /></a><!-- | ||
--><a href="https://github.com/mroderick/PubSubJS/blob/master/LICENSE.md"><img src="https://img.shields.io/npm/l/pubsub-js.svg?style=flat-square" alt="MIT License" title="License" /></a><!-- | ||
--><a href="https://www.npmjs.com/package/pubsub-js"><img src="https://img.shields.io/npm/dm/pubsub-js.svg?style=flat-square" alt="NPM downloads/month" title="Click to go to NPM" /></a><!-- | ||
--><a href="https://coveralls.io/github/mroderick/PubSubJS"><img src="https://img.shields.io/coveralls/github/mroderick/PubSubJS.svg?style=flat-square" alt="Coverage Status" title="View Coverage"/></a> | ||
</p> | ||
</div> | ||
@@ -20,7 +30,7 @@ PubSubJS is a [topic-based](http://en.wikipedia.org/wiki/Publish–subscribe_pattern#Message_filtering) [publish/subscribe](http://en.wikipedia.org/wiki/Publish/subscribe) library written in JavaScript. | ||
* Dependency free | ||
* Synchronization decoupling | ||
* 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 synchronization decoupling) | ||
* Easy to understand and use (thanks to synchronisation decoupling) | ||
* Small(ish), less than 1kb minified and gzipped | ||
@@ -42,2 +52,11 @@ | ||
First you have to import the module: | ||
```javascript | ||
import PubSub from 'pubsub-js' | ||
// or when using CommonJS | ||
const PubSub = require('pubsub-js'); | ||
``` | ||
### Basic example | ||
@@ -56,6 +75,6 @@ | ||
// publish a topic asyncronously | ||
// publish a topic asynchronously | ||
PubSub.publish('MY TOPIC', 'hello world!'); | ||
// publish a topic syncronously, which is faster in some environments, | ||
// publish a topic synchronously, which is faster in some environments, | ||
// but will get confusing when one topic triggers new topics in the | ||
@@ -104,3 +123,3 @@ // same execution chain | ||
PubSub.unsubscribe('a.b'); | ||
// no further notications for 'a.b' and 'a.b.c' topics | ||
// no further notifications for 'a.b' and 'a.b.c' topics | ||
// notifications for 'a' will still get published | ||
@@ -154,3 +173,3 @@ ``` | ||
```javascript | ||
// BAD | ||
// 👎 Bad usage | ||
PubSub.subscribe('hello', function (msg, data) { | ||
@@ -160,5 +179,5 @@ console.log(data) | ||
PubSub.publish('helo', 'world'); | ||
PubSub.publish('hello', 'world'); | ||
// BETTER | ||
// 👍 Better usage | ||
var MY_TOPIC = 'hello'; | ||
@@ -174,3 +193,3 @@ PubSub.subscribe(MY_TOPIC, function (msg, data) { | ||
As of version 1.3.2, you can force immediate exceptions (instead of delayed execeptions), which has the benefit of maintaining the stack trace when viewed in dev 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. | ||
@@ -215,2 +234,2 @@ 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. | ||
* 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 | ||
* https://github.com/pmelander/Subtopic - supports vanilla, underscore, jQuery and is even available in NuGet |
@@ -1,7 +0,8 @@ | ||
/* | ||
Copyright (c) 2010,2011,2012,2013,2014 Morgan Roderick http://roderick.dk | ||
License: MIT - http://mrgnrdrck.mit-license.org | ||
/** | ||
* Copyright (c) 2010,2011,2012,2013,2014 Morgan Roderick http://roderick.dk | ||
* License: MIT - http://mrgnrdrck.mit-license.org | ||
* | ||
* https://github.com/mroderick/PubSubJS | ||
*/ | ||
https://github.com/mroderick/PubSubJS | ||
*/ | ||
(function (root, factory){ | ||
@@ -48,5 +49,7 @@ 'use strict'; | ||
/** | ||
* Returns a function that throws the passed exception, for use as argument for setTimeout | ||
* @param { Object } ex An Error object | ||
*/ | ||
* Returns a function that throws the passed exception, for use as argument for setTimeout | ||
* @alias throwException | ||
* @function | ||
* @param { Object } ex An Error object | ||
*/ | ||
function throwException( ex ){ | ||
@@ -134,7 +137,9 @@ return function reThrowException(){ | ||
/** | ||
* PubSub.publish( message[, data] ) -> Boolean | ||
* - message (String): The message to publish | ||
* - data: The data to pass to subscribers | ||
* Publishes the the message, passing the data to it's subscribers | ||
**/ | ||
* Publishes the message, passing the data to it's subscribers | ||
* @function | ||
* @alias publish | ||
* @param { String } message The message to publish | ||
* @param {} data The data to pass to subscribers | ||
* @return { Boolean } | ||
*/ | ||
PubSub.publish = function( message, data ){ | ||
@@ -145,7 +150,9 @@ return publish( message, data, false, PubSub.immediateExceptions ); | ||
/** | ||
* PubSub.publishSync( message[, data] ) -> Boolean | ||
* - message (String): The message to publish | ||
* - data: The data to pass to subscribers | ||
* Publishes the the message synchronously, passing the data to it's subscribers | ||
**/ | ||
* Publishes the the message synchronously, passing the data to it's subscribers | ||
* @function | ||
* @alias publishSync | ||
* @param { String } message The message to publish | ||
* @param {} data The data to pass to subscribers | ||
* @return { Boolean } | ||
*/ | ||
PubSub.publishSync = function( message, data ){ | ||
@@ -156,8 +163,9 @@ return publish( message, data, true, PubSub.immediateExceptions ); | ||
/** | ||
* PubSub.subscribe( message, func ) -> String | ||
* - message (String): The message to subscribe to | ||
* - func (Function): The function to call when a new message is published | ||
* Subscribes the passed function to the passed message. Every returned token is unique and should be stored if | ||
* you need to unsubscribe | ||
**/ | ||
* Subscribes the passed function to the passed message. Every returned token is unique and should be stored if you need to unsubscribe | ||
* @function | ||
* @alias subscribe | ||
* @param { String } message The message to subscribe to | ||
* @param { Function } func The function to call when a new message is published | ||
* @return { String } | ||
*/ | ||
PubSub.subscribe = function( message, func ){ | ||
@@ -183,7 +191,9 @@ if ( typeof func !== 'function'){ | ||
/** | ||
* PubSub.subscribeOnce( message, func ) -> PubSub | ||
* - message (String): The message to subscribe to | ||
* - func (Function): The function to call when a new message is published | ||
* Subscribes the passed function to the passed message once | ||
**/ | ||
* Subscribes the passed function to the passed message once | ||
* @function | ||
* @alias subscribeOnce | ||
* @param { String } message The message to subscribe to | ||
* @param { Function } func The function to call when a new message is published | ||
* @return { PubSub } | ||
*/ | ||
PubSub.subscribeOnce = function( message, func ){ | ||
@@ -198,4 +208,8 @@ var token = PubSub.subscribe( message, function(){ | ||
/* Public: Clears all subscriptions | ||
*/ | ||
/** | ||
* Clears all subscriptions | ||
* @function | ||
* @public | ||
* @alias clearAllSubscriptions | ||
*/ | ||
PubSub.clearAllSubscriptions = function clearAllSubscriptions(){ | ||
@@ -205,4 +219,8 @@ messages = {}; | ||
/*Public: Clear subscriptions by the topic | ||
*/ | ||
/** | ||
* Clear subscriptions by the topic | ||
* @function | ||
* @public | ||
* @alias clearAllSubscriptions | ||
*/ | ||
PubSub.clearSubscriptions = function clearSubscriptions(topic){ | ||
@@ -217,21 +235,22 @@ var m; | ||
/* Public: removes subscriptions. | ||
* When passed a token, removes a specific subscription. | ||
* When passed a function, removes all subscriptions for that function | ||
* When passed a topic, removes all subscriptions for that topic (hierarchy) | ||
* | ||
* value - A token, function or topic to unsubscribe. | ||
* | ||
* Examples | ||
* | ||
* // Example 1 - unsubscribing with a token | ||
* var token = PubSub.subscribe('mytopic', myFunc); | ||
* PubSub.unsubscribe(token); | ||
* | ||
* // Example 2 - unsubscribing with a function | ||
* PubSub.unsubscribe(myFunc); | ||
* | ||
* // Example 3 - unsubscribing a topic | ||
* PubSub.unsubscribe('mytopic'); | ||
*/ | ||
/** | ||
* Removes subscriptions | ||
* | ||
* - When passed a token, removes a specific subscription. | ||
* | ||
* - When passed a function, removes all subscriptions for that function | ||
* | ||
* - When passed a topic, removes all subscriptions for that topic (hierarchy) | ||
* @function | ||
* @public | ||
* @alias subscribeOnce | ||
* @param { String | Function } value A token, function or topic to unsubscribe from | ||
* @example // Unsubscribing with a token | ||
* var token = PubSub.subscribe('mytopic', myFunc); | ||
* PubSub.unsubscribe(token); | ||
* @example // Unsubscribing with a function | ||
* PubSub.unsubscribe(myFunc); | ||
* @example // Unsubscribing from a topic | ||
* PubSub.unsubscribe('mytopic'); | ||
*/ | ||
PubSub.unsubscribe = function(value){ | ||
@@ -238,0 +257,0 @@ var descendantTopicExists = function(topic) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
227
48221
6
15
952