frntnd-class-with-plugins
Version:
Class that can be extended using plugins
1,548 lines (412 loc) • 18.1 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: ClassWithPlugins</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: ClassWithPlugins</h1>
<section>
<header>
<h2>
ClassWithPlugins
</h2>
<div class="class-description">A basic class that has can be extended using plugins</div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="ClassWithPlugins"><span class="type-signature"></span>new ClassWithPlugins<span class="signature">(options)</span><span class="type-signature"></span></h4>
<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>options</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">the object the instance will be extended with</td>
</tr>
</tbody>
</table>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>plugins</code></td>
<td class="type">
<span class="param-type">Array.<String></span>
</td>
<td class="description last">Array of plugin names to use in this class</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ClassWithPlugins.js.html">ClassWithPlugins.js</a>, <a href="ClassWithPlugins.js.html#line33">line 33</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="plugins"><span class="type-signature"></span>plugins<span class="type-signature"> :Object</span></h4>
<div class="description">
Object containing all plugins for all types, in plugins[type][name] hierarchy
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Object</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ClassWithPlugins.js.html">ClassWithPlugins.js</a>, <a href="ClassWithPlugins.js.html#line50">line 50</a>
</li></ul></dd>
</dl>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id=".hook"><span class="type-signature">(static) </span>hook<span class="signature">(event, cb, context, instance)</span><span class="type-signature"></span></h4>
<div class="description">
This methods registers a hook callback on an instance of a <a href="ClassWithPlugins.html"><code>ClassWithPlugins</code></a>,
it is called by the framework. This should never be called manually, if you want to register a hook,
create a plugin and add it to the plugins of the class.
If you want to fire a hook, use that instance (non static) hook method.
</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">String</span>
</td>
<td class="description last">The hook event to hook into</td>
</tr>
<tr>
<td class="name"><code>cb</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="description last">Callback function, gets ran when this hook executes</td>
</tr>
<tr>
<td class="name"><code>context</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">Context the callbacks should be called with</td>
</tr>
<tr>
<td class="name"><code>instance</code></td>
<td class="type">
<span class="param-type"><a href="ClassWithPlugins.html">ClassWithPlugins</a></span>
</td>
<td class="description last">The instance to hook plugins for</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ClassWithPlugins.js.html">ClassWithPlugins.js</a>, <a href="ClassWithPlugins.js.html#line166">line 166</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".registerPlugin"><span class="type-signature">(static) </span>registerPlugin<span class="signature">(type, name, plugin)</span><span class="type-signature"> → {*}</span></h4>
<div class="description">
Registers a plugin
</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>type</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">The type this is a plugin for, mapped onto a Class using the static get _type property on the class</td>
</tr>
<tr>
<td class="name"><code>name</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Name of the plugin, this is how the plugin is identified in the system, the name is local to its type</td>
</tr>
<tr>
<td class="name"><code>plugin</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">The plugin itself</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ClassWithPlugins.js.html">ClassWithPlugins.js</a>, <a href="ClassWithPlugins.js.html#line63">line 63</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">*</span>
</dd>
</dl>
<h4 class="name" id=".retrievePlugin"><span class="type-signature">(static) </span>retrievePlugin<span class="signature">(type, name)</span><span class="type-signature"> → {Object|undefined}</span></h4>
<div class="description">
Retrieves a plugin
</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>type</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">The type this is a plugin for</td>
</tr>
<tr>
<td class="name"><code>name</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Name of the plugin</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ClassWithPlugins.js.html">ClassWithPlugins.js</a>, <a href="ClassWithPlugins.js.html#line83">line 83</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Object</span>
|
<span class="param-type">undefined</span>
</dd>
</dl>
<h4 class="name" id="hasPlugin"><span class="type-signature"></span>hasPlugin<span class="signature">(plugin)</span><span class="type-signature"> → {Boolean}</span></h4>
<div class="description">
Checks whether this instance has a certain plugin provided using the plugin parameter as a string.
</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>plugin</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Plugin to look for</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ClassWithPlugins.js.html">ClassWithPlugins.js</a>, <a href="ClassWithPlugins.js.html#line151">line 151</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Boolean</span>
</dd>
</dl>
<h4 class="name" id="hook"><span class="type-signature"></span>hook<span class="signature">(event, data)</span><span class="type-signature"> → {Promise}</span></h4>
<div class="description">
Runs all hook listeners from all plugins active on the class,
returns a promise so plugins can do async stuff and you can wait for the plugins to finish.
</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">String</span>
</td>
<td class="description last">Hook event to trigger</td>
</tr>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">Data to supply the hook callback with, in addition to the instance it's called from</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ClassWithPlugins.js.html">ClassWithPlugins.js</a>, <a href="ClassWithPlugins.js.html#line182">line 182</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
</dd>
</dl>
<h4 class="name" id="on"><span class="type-signature"></span>on<span class="signature">(event, cb)</span><span class="type-signature"></span></h4>
<div class="description">
Listens for an event trigger by the <a href="ClassWithPlugins.html#trigger"><code>ClassWithPlugins#trigger</code></a> method
</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">String</span>
</td>
<td class="description last">Event to listen to.</td>
</tr>
<tr>
<td class="name"><code>cb</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="description last">Function that should be called when this event is triggered.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ClassWithPlugins.js.html">ClassWithPlugins.js</a>, <a href="ClassWithPlugins.js.html#line122">line 122</a>
</li></ul></dd>
</dl>
<h4 class="name" id="trigger"><span class="type-signature"></span>trigger<span class="signature">(event, data)</span><span class="type-signature"></span></h4>
<div class="description">
Triggers an event with data that can be listed to using the <a href="ClassWithPlugins.html#on"><code>ClassWithPlugins#on</code></a> method
</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">String</span>
</td>
<td class="description last">Event to trigger.</td>
</tr>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type">*</span>
</td>
<td class="description last">Data the event should trigger with.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ClassWithPlugins.js.html">ClassWithPlugins.js</a>, <a href="ClassWithPlugins.js.html#line137">line 137</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="ClassWithPlugins.html">ClassWithPlugins</a></li></ul><h3>Tutorials</h3><ul><li><a href="tutorial-README.html">README</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.3</a> on Thu Sep 24 2015 22:53:49 GMT+0200 (CEST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>