UNPKG

nx-event-bus

Version:

Simple JavaScript Event Bus Implementation

2,135 lines (525 loc) 23.7 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: EventBus</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Class: EventBus</h1> <section> <header> <h2><span class="attribs"><span class="type-signature"></span></span>EventBus<span class="signature">(name)</span><span class="type-signature"></span></h2> </header> <article> <div class="container-overview"> <h4 class="name" id="EventBus"><span class="type-signature"></span>new EventBus<span class="signature">(name)</span><span class="type-signature"></span></h4> <div class="description"> The event bus constructor </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">[description]</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="nx-event-bus.js.html">nx-event-bus.js</a>, <a href="nx-event-bus.js.html#line165">line 165</a> </li></ul></dd> </dl> </div> <h3 class="subsection-title">Members</h3> <h4 class="name" id=".BusEvent"><span class="type-signature">(static) </span>BusEvent<span class="type-signature"></span></h4> <div class="description"> Return the BusEvent class </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="nx-event-bus.js.html">nx-event-bus.js</a>, <a href="nx-event-bus.js.html#line158">line 158</a> </li></ul></dd> </dl> <h4 class="name" id=".Errors"><span class="type-signature">(static) </span>Errors<span class="type-signature"></span></h4> <div class="description"> Return all the errors type </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="nx-event-bus.js.html">nx-event-bus.js</a>, <a href="nx-event-bus.js.html#line149">line 149</a> </li></ul></dd> </dl> <h4 class="name" id="name"><span class="type-signature"></span>name<span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="nx-event-bus.js.html">nx-event-bus.js</a>, <a href="nx-event-bus.js.html#line175">line 175</a> </li></ul></dd> </dl> <h3 class="subsection-title">Methods</h3> <h4 class="name" id=".deregister"><span class="type-signature">(static) </span>deregister<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> Deregister a function from the event bus </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="nx-event-bus.js.html">nx-event-bus.js</a>, <a href="nx-event-bus.js.html#line331">line 331</a> </li></ul></dd> <dt class="tag-see">See:</dt> <dd class="tag-see"> <ul> <li><a href="EventBus.html#.deregister">EventBus.deregister</a></li> </ul> </dd> </dl> <h4 class="name" id=".emit"><span class="type-signature">(static) </span>emit<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> Emit an event to a channel </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="nx-event-bus.js.html">nx-event-bus.js</a>, <a href="nx-event-bus.js.html#line339">line 339</a> </li></ul></dd> <dt class="tag-see">See:</dt> <dd class="tag-see"> <ul> <li><a href="EventBus.html#.emit">EventBus.emit</a></li> </ul> </dd> </dl> <h4 class="name" id=".register"><span class="type-signature">(static) </span>register<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> Method used to register a callback function on a specific channel </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="nx-event-bus.js.html">nx-event-bus.js</a>, <a href="nx-event-bus.js.html#line323">line 323</a> </li></ul></dd> <dt class="tag-see">See:</dt> <dd class="tag-see"> <ul> <li><a href="EventBus.html#.register">EventBus.register</a></li> </ul> </dd> </dl> <h4 class="name" id="deregister"><span class="type-signature"></span>deregister<span class="signature">(channel, listener)</span><span class="type-signature"></span></h4> <div class="description"> Deregister a function from the event bus </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>channel</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The listening channel</td> </tr> <tr> <td class="name"><code>listener</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">The listener function</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="nx-event-bus.js.html">nx-event-bus.js</a>, <a href="nx-event-bus.js.html#line225">line 225</a> </li></ul></dd> </dl> <h4 class="name" id="destroy"><span class="type-signature"></span>destroy<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> Destroy the event bus </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="nx-event-bus.js.html">nx-event-bus.js</a>, <a href="nx-event-bus.js.html#line344">line 344</a> </li></ul></dd> </dl> <h4 class="name" id="emit"><span class="type-signature"></span>emit<span class="signature">(channel, data)</span><span class="type-signature"> &rarr; {<a href="EventBus.html">EventBus</a>}</span></h4> <div class="description"> Emit an event to a channel </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>channel</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The event channel</td> </tr> <tr> <td class="name"><code>data</code></td> <td class="type"> <span class="param-type">*</span> </td> <td class="description last">The event data</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="nx-event-bus.js.html">nx-event-bus.js</a>, <a href="nx-event-bus.js.html#line246">line 246</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Returns the current instance of the EventBus </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="EventBus.html">EventBus</a></span> </dd> </dl> <h4 class="name" id="emitAsync"><span class="type-signature"></span>emitAsync<span class="signature">(channel, data, delay=<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {<a href="EventBus.html">EventBus</a>}</span></h4> <div class="description"> Method to emit an event async </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>channel</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">The event channel</td> </tr> <tr> <td class="name"><code>data</code></td> <td class="type"> <span class="param-type">*</span> </td> <td class="attributes"> </td> <td class="description last">The event data</td> </tr> <tr> <td class="name"><code>delay=</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">The delay until the event will be send</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="nx-event-bus.js.html">nx-event-bus.js</a>, <a href="nx-event-bus.js.html#line298">line 298</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Returns the current instance of the EventBus </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="EventBus.html">EventBus</a></span> </dd> </dl> <h4 class="name" id="emitEvent"><span class="type-signature"></span>emitEvent<span class="signature">(event)</span><span class="type-signature"></span></h4> <div class="description"> Emit a bus event </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>event</code></td> <td class="type"> <span class="param-type"><a href="BusEvent.html">BusEvent</a></span> </td> <td class="description last">[description]</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="nx-event-bus.js.html">nx-event-bus.js</a>, <a href="nx-event-bus.js.html#line261">line 261</a> </li></ul></dd> </dl> <h4 class="name" id="register"><span class="type-signature"></span>register<span class="signature">(channel, listener, scope=<span class="signature-attributes">opt</span>, once<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {function}</span></h4> <div class="description"> Method used to register a callback function on a specific channel </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>channel</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">The given channel</td> </tr> <tr> <td class="name"><code>listener</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">The callback function</td> </tr> <tr> <td class="name"><code>scope=</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last">The callback function scope</td> </tr> <tr> <td class="name"><code>once</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> false </td> <td class="description last">If it should deregister after first event</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="nx-event-bus.js.html">nx-event-bus.js</a>, <a href="nx-event-bus.js.html#line188">line 188</a> </li></ul></dd> </dl> <h5>Throws:</h5> <dl> <dt> <div class="param-desc"> If [this condition is met] </div> </dt> <dd></dd> <dt> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="InvalidParameterGiven.html">InvalidParameterGiven</a></span> </dd> </dl> </dt> <dd></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Returns a deregister function </div> <dl> <dt> Type </dt> <dd> <span class="param-type">function</span> </dd> </dl> <h4 class="name" id="registerOnce"><span class="type-signature"></span>registerOnce<span class="signature">(channel, listener, scope=<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {function}</span></h4> <div class="description"> Method used to register a callback function on a specific channel </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>channel</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">The given channel</td> </tr> <tr> <td class="name"><code>listener</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> </td> <td class="description last">The callback function</td> </tr> <tr> <td class="name"><code>scope=</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">The callback function scope</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="nx-event-bus.js.html">nx-event-bus.js</a>, <a href="nx-event-bus.js.html#line215">line 215</a> </li></ul></dd> </dl> <h5>Throws:</h5> <dl> <dt> <div class="param-desc"> If [this condition is met] </div> </dt> <dd></dd> <dt> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="InvalidParameterGiven.html">InvalidParameterGiven</a></span> </dd> </dl> </dt> <dd></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Returns a deregister function </div> <dl> <dt> Type </dt> <dd> <span class="param-type">function</span> </dd> </dl> <h4 class="name" id="resendDeadEvents"><span class="type-signature"></span>resendDeadEvents<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> Start resending 'dead' events </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="nx-event-bus.js.html">nx-event-bus.js</a>, <a href="nx-event-bus.js.html#line306">line 306</a> </li></ul></dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BusEvent.html">BusEvent</a></li><li><a href="EventBus.html">EventBus</a></li><li><a href="EventListener.html">EventListener</a></li><li><a href="InvalidParameterGiven.html">InvalidParameterGiven</a></li></ul><h3>Global</h3><ul><li><a href="global.html#isFunction">isFunction</a></li><li><a href="global.html#toString">toString</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat Aug 18 2018 21:30:07 GMT+0100 (BST) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>