You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
--><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><!--
9
+
--><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><!--
10
+
--><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://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><!--
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.
8
18
9
-
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.
19
+
PubSubJS has synchronization 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.
10
20
11
21
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.
12
22
@@ -38,6 +48,15 @@ There are several ways of getting PubSubJS
38
48
39
49
## Examples
40
50
51
+
First you have to import the module:
52
+
53
+
```javascript
54
+
importPubSubfrom'pubsub-js'
55
+
56
+
// or when using CommonJS
57
+
constPubSub=require('pubsub-js');
58
+
```
59
+
41
60
### Basic example
42
61
43
62
```javascript
@@ -51,10 +70,10 @@ var mySubscriber = function (msg, data) {
51
70
// from the topic later on
52
71
var token =PubSub.subscribe('MY TOPIC', mySubscriber);
53
72
54
-
// publish a topic asyncronously
73
+
// publish a topic asynchronously
55
74
PubSub.publish('MY TOPIC', 'hello world!');
56
75
57
-
// publish a topic syncronously, which is faster in some environments,
76
+
// publish a topic synchronously, which is faster in some environments,
58
77
// but will get confusing when one topic triggers new topics in the
### Immediate Exceptions for stack traces in developer tools
167
186
168
-
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.
187
+
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.
169
188
170
189
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.
171
190
@@ -205,4 +224,4 @@ These are a few alternative projects that also implement topic based publish sub
0 commit comments