Skip to content

Commit 889602c

Browse files
authored
Merge pull request #6 from a-bugaj/chore/docs
chore: Documentation
2 parents 39ec7af + 1fab973 commit 889602c

File tree

1 file changed

+27
-37
lines changed

1 file changed

+27
-37
lines changed

README.md

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
# awesome-pubsub-js
22

3+
[![NPM](https://img.shields.io/npm/v/awesome-pubsub-js.svg)](https://www.npmjs.com/package/awesome-pubsub-js) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
4+
35
JavaScript implementation of the Publish/Subscribe pattern with TypeScript support.
46

57
# Install
68

79
### npm
810

9-
```sh
11+
```shell
1012
$ npm install awesome-pubsub-js
1113
```
1214

13-
### Example
15+
### yarn
16+
```shell
17+
$ yarn add awesome-pubsub-js
18+
```
19+
20+
# A quick example
21+
22+
Do you want to know more? Go to the [Documentation](#API) section
1423

1524
##### JavaScript:
1625

@@ -27,46 +36,27 @@ pubSub.subscribe("event.example", (data) => {
2736
pubSub.publish("event.example", { name: "John", email: "john@gmail.com" });
2837
```
2938

30-
##### TypeScript:
39+
### API
40+
**List of all available methods:**
3141

32-
```ts
33-
import PubSub from "awesome-pubsub-js";
42+
Each of the following methods takes one or two arguments
3443

35-
const pubSub = PubSub();
36-
37-
interface Data {
38-
name: string;
39-
age: number;
40-
}
44+
- Subscribe
4145

42-
const data: Data = { name: "John", age: 40 };
43-
44-
pubSub.subscribe<string, Data>("event.example", (data) => {
45-
// data = { name: "John", age: 40 }
46-
// ... your logic
47-
});
48-
pubSub.publish("event.example", data);
49-
50-
// or with enum
51-
52-
enum Event {
53-
Example: "event.example"
54-
}
55-
56-
pubSub.subscribe<Event, Data>(Event.Example, data => {
57-
// data = { name: "John", age: 20 }
58-
// ... your logic
59-
});
60-
pubSub.publish<Event, Data>(Event.Example, data);
61-
62-
pubSub.subscribe<Event.Example, Data>(Event.Example, data => {});
63-
pubSub.publish<Event.Example>(Event.Example, data);
64-
```
6546

66-
### Documentation
47+
| Method name | Payload | Return value |
48+
| ------ | ------ | ------ |
49+
| subscribe | ```pubSub.subscribe("eventName", (data) => {});```| HashKey (string) - is needed for use in the 'unsubscribe' method |
50+
| unsubscribe | ```pubSub.unsubscribe('hashKey')``` <br /> hashKey (string) is always returned from the subscribe method | true - when the event has been successfully unsubscribed <br /> false - when the event does not exists |
51+
| publish | ```pubSub.publish('eventName', any)``` <br /> any = literally anything you want to pass :) <br /> If you don't pass anything, the default value will be undefined | true - when the event has published successfully <br /> false - when the event has not been published (e.g. due to the lack of a registered subscriber) |
52+
| getAllSubscribers | - | returns the current subscription list |
6753

68-
TODO
6954

7055
### Roadmap:
7156

72-
TODO
57+
- [x] subscribe and publish method
58+
- [x] unsubscribe method
59+
- [x] getAllSubscribers method
60+
- [ ] Wildcard support
61+
- [ ] Logger
62+

0 commit comments

Comments
 (0)