Skip to content

Commit 6d946a0

Browse files
favnamroderick
authored andcommitted
Cleanup readme
Resolves mroderick#114 Closes mroderick#118
1 parent 75fb9f7 commit 6d946a0

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

README.md

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
# PubSubJS
2-
3-
[![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)
4-
![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)
5-
[![Coverage Status](https://coveralls.io/repos/github/mroderick/PubSubJS/badge.svg)](https://coveralls.io/github/mroderick/PubSubJS)
1+
<div align="center">
2+
<p>
3+
<h1> PubSubJS
4+
</p>
5+
6+
<p>
7+
<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><!--
8+
--><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><!--
11+
--><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><!--
12+
--><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><!--
13+
--><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>
14+
</p>
15+
</div>
616

717
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.
818

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.
1020

1121
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.
1222

@@ -38,6 +48,15 @@ There are several ways of getting PubSubJS
3848

3949
## Examples
4050

51+
First you have to import the module:
52+
53+
```javascript
54+
import PubSub from 'pubsub-js'
55+
56+
// or when using CommonJS
57+
const PubSub = require('pubsub-js');
58+
```
59+
4160
### Basic example
4261

4362
```javascript
@@ -51,10 +70,10 @@ var mySubscriber = function (msg, data) {
5170
// from the topic later on
5271
var token = PubSub.subscribe('MY TOPIC', mySubscriber);
5372

54-
// publish a topic asyncronously
73+
// publish a topic asynchronously
5574
PubSub.publish('MY TOPIC', 'hello world!');
5675

57-
// publish a topic syncronously, which is faster in some environments,
76+
// publish a topic synchronously, which is faster in some environments,
5877
// but will get confusing when one topic triggers new topics in the
5978
// same execution chain
6079
// USE WITH CAUTION, HERE BE DRAGONS!!!
@@ -98,7 +117,7 @@ PubSub.subscribe('a.b', myFunc2);
98117
PubSub.subscribe('a.b.c', myFunc3);
99118

100119
PubSub.unsubscribe('a.b');
101-
// no further notications for 'a.b' and 'a.b.c' topics
120+
// no further notifications for 'a.b' and 'a.b.c' topics
102121
// notifications for 'a' will still get published
103122
```
104123

@@ -147,14 +166,14 @@ when you make typos.
147166
### Example of use of "constants"
148167

149168
```javascript
150-
// BAD
169+
// 👎 Bad usage
151170
PubSub.subscribe('hello', function (msg, data) {
152171
console.log(data)
153172
});
154173

155-
PubSub.publish('helo', 'world');
174+
PubSub.publish('hello', 'world');
156175

157-
// BETTER
176+
// 👍 Better usage
158177
var MY_TOPIC = 'hello';
159178
PubSub.subscribe(MY_TOPIC, function (msg, data) {
160179
console.log(data)
@@ -165,7 +184,7 @@ PubSub.publish(MY_TOPIC, 'world');
165184

166185
### Immediate Exceptions for stack traces in developer tools
167186

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.
169188

170189
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.
171190

@@ -205,4 +224,4 @@ These are a few alternative projects that also implement topic based publish sub
205224
* http://www.joezimjs.com/projects/publish-subscribe-jquery-plugin/
206225
* http://amplifyjs.com/api/pubsub/
207226
* http://radio.uxder.com/ — oriented towards 'channels', free of dependencies
208-
* https://github.com/pmelander/Subtopic - supports vanilla, underscore, jQuery and is even available in NuGet
227+
* https://github.com/pmelander/Subtopic - supports vanilla, underscore, jQuery and is even available in NuGet

0 commit comments

Comments
 (0)