Skip to content

Commit d5b9fbf

Browse files
committed
Update docs
1 parent fd7933a commit d5b9fbf

File tree

1 file changed

+172
-0
lines changed

1 file changed

+172
-0
lines changed

docs/docs.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
Documentation is generated by [JSDoc](https://github.com/jsdoc3/jsdoc) and [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).
2+
3+
***
4+
5+
## Functions
6+
7+
<dl>
8+
<dt><a href="#throwException">throwException(ex)</a></dt>
9+
<dd><p>Returns a function that throws the passed exception, for use as argument for setTimeout</p>
10+
</dd>
11+
<dt><a href="#publish">publish(message, data)</a> ⇒ <code>Boolean</code></dt>
12+
<dd><p>Publishes the message, passing the data to it&#39;s subscribers</p>
13+
</dd>
14+
<dt><a href="#publishSync">publishSync(message, data)</a> ⇒ <code>Boolean</code></dt>
15+
<dd><p>Publishes the message synchronously, passing the data to it&#39;s subscribers</p>
16+
</dd>
17+
<dt><a href="#subscribe">subscribe(message, func)</a> ⇒ <code>String</code></dt>
18+
<dd><p>Subscribes the passed function to the passed message. Every returned token is unique and should be stored if you need to unsubscribe</p>
19+
</dd>
20+
<dt><a href="#subscribeOnce">subscribeOnce(message, func)</a> ⇒ <code>PubSub</code></dt>
21+
<dd><p>Subscribes the passed function to the passed message once</p>
22+
</dd>
23+
<dt><a href="#clearAllSubscriptions">clearAllSubscriptions()</a></dt>
24+
<dd><p>Clears all subscriptions</p>
25+
</dd>
26+
<dt><a href="#clearAllSubscriptions">clearAllSubscriptions()</a> ⇒ <code>int</code></dt>
27+
<dd><p>Clear subscriptions by the topic</p>
28+
</dd>
29+
<dt><a href="#countSubscriptions">countSubscriptions()</a> ⇒ <code>Array</code></dt>
30+
<dd><p>Count subscriptions by the topic</p>
31+
</dd>
32+
<dt><a href="#getSubscriptions">getSubscriptions()</a></dt>
33+
<dd><p>Gets subscriptions by the topic</p>
34+
</dd>
35+
<dt><a href="#subscribeOnce">subscribeOnce(value)</a></dt>
36+
<dd><p>Removes subscriptions</p>
37+
<ul>
38+
<li><p>When passed a token, removes a specific subscription.</p>
39+
</li>
40+
<li><p>When passed a function, removes all subscriptions for that function</p>
41+
</li>
42+
<li><p>When passed a topic, removes all subscriptions for that topic (hierarchy)</p>
43+
</li>
44+
</ul>
45+
</dd>
46+
</dl>
47+
48+
<a name="throwException"></a>
49+
50+
## throwException(ex)
51+
Returns a function that throws the passed exception, for use as argument for setTimeout
52+
53+
**Kind**: global function
54+
55+
| Param | Type | Description |
56+
| --- | --- | --- |
57+
| ex | <code>Object</code> | An Error object |
58+
59+
<a name="publish"></a>
60+
61+
## publish(message, data) ⇒ <code>Boolean</code>
62+
Publishes the message, passing the data to it's subscribers
63+
64+
**Kind**: global function
65+
66+
| Param | Type | Description |
67+
| --- | --- | --- |
68+
| message | <code>String</code> | The message to publish |
69+
| data | | The data to pass to subscribers |
70+
71+
<a name="publishSync"></a>
72+
73+
## publishSync(message, data) ⇒ <code>Boolean</code>
74+
Publishes the message synchronously, passing the data to it's subscribers
75+
76+
**Kind**: global function
77+
78+
| Param | Type | Description |
79+
| --- | --- | --- |
80+
| message | <code>String</code> | The message to publish |
81+
| data | | The data to pass to subscribers |
82+
83+
<a name="subscribe"></a>
84+
85+
## subscribe(message, func) ⇒ <code>String</code>
86+
Subscribes the passed function to the passed message. Every returned token is unique and should be stored if you need to unsubscribe
87+
88+
**Kind**: global function
89+
90+
| Param | Type | Description |
91+
| --- | --- | --- |
92+
| message | <code>String</code> | The message to subscribe to |
93+
| func | <code>function</code> | The function to call when a new message is published |
94+
95+
<a name="subscribeOnce"></a>
96+
97+
## subscribeOnce(message, func) ⇒ <code>PubSub</code>
98+
Subscribes the passed function to the passed message once
99+
100+
**Kind**: global function
101+
102+
| Param | Type | Description |
103+
| --- | --- | --- |
104+
| message | <code>String</code> | The message to subscribe to |
105+
| func | <code>function</code> | The function to call when a new message is published |
106+
107+
<a name="clearAllSubscriptions"></a>
108+
109+
## clearAllSubscriptions()
110+
Clears all subscriptions
111+
112+
**Kind**: global function
113+
**Access**: public
114+
<a name="clearAllSubscriptions"></a>
115+
116+
## clearAllSubscriptions() ⇒ <code>int</code>
117+
Clear subscriptions by the topic
118+
119+
**Kind**: global function
120+
**Access**: public
121+
<a name="countSubscriptions"></a>
122+
123+
## countSubscriptions() ⇒ <code>Array</code>
124+
Count subscriptions by the topic
125+
126+
**Kind**: global function
127+
**Access**: public
128+
<a name="getSubscriptions"></a>
129+
130+
## getSubscriptions()
131+
Gets subscriptions by the topic
132+
133+
**Kind**: global function
134+
**Access**: public
135+
<a name="subscribeOnce"></a>
136+
137+
## subscribeOnce(value)
138+
Removes subscriptions
139+
140+
- When passed a token, removes a specific subscription.
141+
142+
- When passed a function, removes all subscriptions for that function
143+
144+
- When passed a topic, removes all subscriptions for that topic (hierarchy)
145+
146+
**Kind**: global function
147+
**Access**: public
148+
149+
| Param | Type | Description |
150+
| --- | --- | --- |
151+
| value | <code>String</code> \| <code>function</code> | A token, function or topic to unsubscribe from |
152+
153+
**Example**
154+
```js
155+
// Unsubscribing with a token
156+
var token = PubSub.subscribe('mytopic', myFunc);
157+
PubSub.unsubscribe(token);
158+
```
159+
**Example**
160+
```js
161+
// Unsubscribing with a function
162+
PubSub.unsubscribe(myFunc);
163+
```
164+
**Example**
165+
```js
166+
// Unsubscribing from a topic
167+
PubSub.unsubscribe('mytopic');
168+
```
169+
170+
* * *
171+
172+
&copy; 2018 [Morgan Roderick](https://roderick.dk), [http://roderick.dk/](https://roderick.dk) <[morgan@roderick.dk](mailto:morgan@roderick.dk)>

0 commit comments

Comments
 (0)