Skip to content

Commit

Permalink
Merge pull request #12 from xtitusx/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
xtitusx committed Dec 14, 2022
2 parents 02a268e + 3daf85b commit 16c1d85
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 28 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ eventBus.publish<HelloWorldMessage>(HelloWorldEvent, {

### clear()

Removes all subscribers:
- Removes all subscribers:

```
const eventBus = new EventBus();
Expand All @@ -163,6 +163,26 @@ eventBus.publish<HelloWorldMessage>(HelloWorldEvent, {
// => Nothing
```

- Or removes only subscribers for the specified event:

```
const eventBus = new EventBus();
eventBus.subscribe(HelloWorldEvent, new HelloWorldEventSubscriber());
eventBus.publish<HelloWorldMessage>(HelloWorldEvent, {
name: 'Benjamin',
});
// => 'Hello Benjamin!'
eventBus.clear(HelloWorldEvent);
eventBus.publish<HelloWorldMessage>(HelloWorldEvent, {
name: 'Benjamin',
});
// => Nothing
```

## Subscription

### unsubscribe()
Expand Down
2 changes: 1 addition & 1 deletion docs/classes/event.Event.html
Original file line number Diff line number Diff line change
Expand Up @@ -2771,7 +2771,7 @@ <h3>name</h3>
<div class="tsd-signature tsd-kind-icon">name<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> = ...</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event.ts#L2">event.ts:2</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event.ts#L2">event.ts:2</a></li>
</ul>
</aside>
</section>
Expand Down
24 changes: 12 additions & 12 deletions docs/classes/event_bus.EventBus.html
Original file line number Diff line number Diff line change
Expand Up @@ -2815,7 +2815,7 @@ <h3>constructor</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L62">event-bus.ts:62</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L62">event-bus.ts:62</a></li>
</ul>
</aside>
<h4 class="tsd-returns-title">Returns <a href="event_bus.EventBus.html" class="tsd-signature-type" data-tsd-kind="Class">EventBus</a></h4>
Expand All @@ -2831,7 +2831,7 @@ <h3><span class="tsd-flag ts-flagPrivate">Private</span> count</h3>
<div class="tsd-signature tsd-kind-icon">count<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span><span class="tsd-signature-symbol"> = 0</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L60">event-bus.ts:60</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L60">event-bus.ts:60</a></li>
</ul>
</aside>
</section>
Expand All @@ -2841,7 +2841,7 @@ <h3><span class="tsd-flag ts-flagPrivate">Private</span> subscribers<wbr>ByEvent
<div class="tsd-signature tsd-kind-icon">subscribers<wbr>ByEvent<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">ISubscribersByEvent</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L59">event-bus.ts:59</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L59">event-bus.ts:59</a></li>
</ul>
</aside>
</section>
Expand All @@ -2851,7 +2851,7 @@ <h3><span class="tsd-flag ts-flagStatic">Static</span> <span class="tsd-flag ts-
<div class="tsd-signature tsd-kind-icon">INSTANCE<span class="tsd-signature-symbol">:</span> <a href="event_bus.EventBus.html" class="tsd-signature-type" data-tsd-kind="Class">EventBus</a></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L56">event-bus.ts:56</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L56">event-bus.ts:56</a></li>
</ul>
</aside>
</section>
Expand All @@ -2861,7 +2861,7 @@ <h3><span class="tsd-flag ts-flagStatic">Static</span> <span class="tsd-flag ts-
<div class="tsd-signature tsd-kind-icon">MAX_<wbr>ID<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">99</span><span class="tsd-signature-symbol"> = 99</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L57">event-bus.ts:57</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L57">event-bus.ts:57</a></li>
</ul>
</aside>
</section>
Expand All @@ -2879,7 +2879,7 @@ <h3>clear</h3>
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/event_bus.IEventBus.html">IEventBus</a>.<a href="../interfaces/event_bus.IEventBus.html#clear">clear</a></p>
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L129">event-bus.ts:129</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L129">event-bus.ts:129</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -2907,7 +2907,7 @@ <h3><span class="tsd-flag ts-flagPrivate">Private</span> get<wbr>Next<wbr>Id</h3
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L143">event-bus.ts:143</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L143">event-bus.ts:143</a></li>
</ul>
</aside>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">string</span></h4>
Expand All @@ -2924,7 +2924,7 @@ <h3><span class="tsd-flag ts-flagPrivate">Private</span> init<wbr>Event<wbr>Map<
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L137">event-bus.ts:137</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L137">event-bus.ts:137</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -2948,7 +2948,7 @@ <h3>once</h3>
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/event_bus.IEventBus.html">IEventBus</a>.<a href="../interfaces/event_bus.IEventBus.html#once">once</a></p>
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L98">event-bus.ts:98</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L98">event-bus.ts:98</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -2985,7 +2985,7 @@ <h3>publish</h3>
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/event_bus.IEventBus.html">IEventBus</a>.<a href="../interfaces/event_bus.IEventBus.html#publish">publish</a></p>
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L109">event-bus.ts:109</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L109">event-bus.ts:109</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -3023,7 +3023,7 @@ <h3>subscribe</h3>
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/event_bus.IEventBus.html">IEventBus</a>.<a href="../interfaces/event_bus.IEventBus.html#subscribe">subscribe</a></p>
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L77">event-bus.ts:77</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L77">event-bus.ts:77</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -3055,7 +3055,7 @@ <h3><span class="tsd-flag ts-flagStatic">Static</span> get<wbr>Instance</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L69">event-bus.ts:69</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L69">event-bus.ts:69</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
6 changes: 3 additions & 3 deletions docs/classes/subscriber.Subscriber.html
Original file line number Diff line number Diff line change
Expand Up @@ -2776,7 +2776,7 @@ <h3>constructor</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/subscriber.ts#L13">subscriber.ts:13</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/subscriber.ts#L13">subscriber.ts:13</a></li>
</ul>
</aside>
<h4 class="tsd-returns-title">Returns <a href="subscriber.Subscriber.html" class="tsd-signature-type" data-tsd-kind="Class">Subscriber</a></h4>
Expand All @@ -2793,7 +2793,7 @@ <h3>callback</h3>
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/subscriber.ISubscriber.html">ISubscriber</a>.<a href="../interfaces/subscriber.ISubscriber.html#callback">callback</a></p>
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/subscriber.ts#L11">subscriber.ts:11</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/subscriber.ts#L11">subscriber.ts:11</a></li>
</ul>
</aside>
</section>
Expand All @@ -2811,7 +2811,7 @@ <h3><span class="tsd-flag ts-flagAbstract">Abstract</span> impl<wbr>Callback</h3
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/subscriber.ISubscriber.html">ISubscriber</a>.<a href="../interfaces/subscriber.ISubscriber.html#implCallback">implCallback</a></p>
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/subscriber.ts#L17">subscriber.ts:17</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/subscriber.ts#L17">subscriber.ts:17</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
23 changes: 22 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2840,7 +2840,9 @@ <h3>once()</h3>
<a href="#clear" id="clear" style="color: inherit; text-decoration: none;">
<h3>clear()</h3>
</a>
<p>Removes all subscribers:</p>
<ul>
<li>Removes all subscribers:</li>
</ul>
<pre><code><span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">eventBus</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">EventBus</span><span style="color: #000000">();</span>
<span style="color: #001080">eventBus</span><span style="color: #000000">.</span><span style="color: #795E26">subscribe</span><span style="color: #000000">(</span><span style="color: #001080">HelloWorldEvent</span><span style="color: #000000">, </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">HelloWorldEventSubscriber</span><span style="color: #000000">());</span>
<span style="color: #001080">eventBus</span><span style="color: #000000">.</span><span style="color: #795E26">publish</span><span style="color: #000000">&lt;</span><span style="color: #267F99">HelloWorldMessage</span><span style="color: #000000">&gt;(</span><span style="color: #001080">HelloWorldEvent</span><span style="color: #000000">, {</span>
Expand All @@ -2855,6 +2857,25 @@ <h3>clear()</h3>
<span style="color: #000000"> </span><span style="color: #001080">name:</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;Benjamin&#039;</span><span style="color: #000000">,</span>
<span style="color: #000000">});</span>

<span style="color: #008000">// =&gt; Nothing</span>
</code></pre>
<ul>
<li>Or removes only subscribers for the specified event:</li>
</ul>
<pre><code><span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">eventBus</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">EventBus</span><span style="color: #000000">();</span>
<span style="color: #001080">eventBus</span><span style="color: #000000">.</span><span style="color: #795E26">subscribe</span><span style="color: #000000">(</span><span style="color: #001080">HelloWorldEvent</span><span style="color: #000000">, </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">HelloWorldEventSubscriber</span><span style="color: #000000">());</span>
<span style="color: #001080">eventBus</span><span style="color: #000000">.</span><span style="color: #795E26">publish</span><span style="color: #000000">&lt;</span><span style="color: #267F99">HelloWorldMessage</span><span style="color: #000000">&gt;(</span><span style="color: #001080">HelloWorldEvent</span><span style="color: #000000">, {</span>
<span style="color: #000000"> </span><span style="color: #001080">name:</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;Benjamin&#039;</span><span style="color: #000000">,</span>
<span style="color: #000000">});</span>

<span style="color: #008000">// =&gt; &#039;Hello Benjamin!&#039; </span>

<span style="color: #001080">eventBus</span><span style="color: #000000">.</span><span style="color: #795E26">clear</span><span style="color: #000000">(</span><span style="color: #001080">HelloWorldEvent</span><span style="color: #000000">);</span>

<span style="color: #001080">eventBus</span><span style="color: #000000">.</span><span style="color: #795E26">publish</span><span style="color: #000000">&lt;</span><span style="color: #267F99">HelloWorldMessage</span><span style="color: #000000">&gt;(</span><span style="color: #001080">HelloWorldEvent</span><span style="color: #000000">, {</span>
<span style="color: #000000"> </span><span style="color: #001080">name:</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;Benjamin&#039;</span><span style="color: #000000">,</span>
<span style="color: #000000">});</span>

<span style="color: #008000">// =&gt; Nothing</span>
</code></pre>
<a href="#subscription" id="subscription" style="color: inherit; text-decoration: none;">
Expand Down
8 changes: 4 additions & 4 deletions docs/interfaces/event_bus.IEventBus.html
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,7 @@ <h3>clear</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L46">event-bus.ts:46</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L46">event-bus.ts:46</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -2807,7 +2807,7 @@ <h3>once</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L31">event-bus.ts:31</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L31">event-bus.ts:31</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -2847,7 +2847,7 @@ <h3>publish</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L39">event-bus.ts:39</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L39">event-bus.ts:39</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -2890,7 +2890,7 @@ <h3>subscribe</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L22">event-bus.ts:22</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L22">event-bus.ts:22</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
6 changes: 3 additions & 3 deletions docs/interfaces/event_bus.ISubscription.html
Original file line number Diff line number Diff line change
Expand Up @@ -2764,7 +2764,7 @@ <h3>event<wbr>Name</h3>
<div class="tsd-signature tsd-kind-icon">event<wbr>Name<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L6">event-bus.ts:6</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L6">event-bus.ts:6</a></li>
</ul>
</aside>
</section>
Expand All @@ -2774,7 +2774,7 @@ <h3>id</h3>
<div class="tsd-signature tsd-kind-icon">id<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L5">event-bus.ts:5</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L5">event-bus.ts:5</a></li>
</ul>
</aside>
</section>
Expand All @@ -2791,7 +2791,7 @@ <h3>unsubscribe</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/event-bus.ts#L10">event-bus.ts:10</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/event-bus.ts#L10">event-bus.ts:10</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
4 changes: 2 additions & 2 deletions docs/interfaces/subscriber.ISubscriber.html
Original file line number Diff line number Diff line change
Expand Up @@ -2763,7 +2763,7 @@ <h3>callback</h3>
<div class="tsd-signature tsd-kind-icon">callback<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/subscriber.ts#L2">subscriber.ts:2</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/subscriber.ts#L2">subscriber.ts:2</a></li>
</ul>
</aside>
</section>
Expand All @@ -2780,7 +2780,7 @@ <h3>impl<wbr>Callback</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/271c08d/src/subscriber.ts#L7">subscriber.ts:7</a></li>
<li>Defined in <a href="https://github.com/xtitusx/event-bus/blob/ee07f12/src/subscriber.ts#L7">subscriber.ts:7</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
Loading

0 comments on commit 16c1d85

Please sign in to comment.