UNPKG

lfr-amd-loader

Version:

AMD Loader with support for combo URL and conditional loading

2,861 lines (887 loc) 36.6 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: Loader</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: Loader</h1> <section> <header> <h2> Loader </h2> </header> <article> <div class="container-overview"> <dt> <h4 class="name" id="Loader"><span class="type-signature"></span>new Loader<span class="signature">()</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Creates an instance of Loader class. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line3">line 3</a> </li></ul></dd> </dl> </dd> </div> <h3 class="subsection-title">Extends</h3> <ul> <li><a href="EventEmitter.html">EventEmitter</a></li> </ul> <h3 class="subsection-title">Methods</h3> <dl> <dt> <h4 class="name" id="_createModulePromise"><span class="type-signature">&lt;protected> </span>_createModulePromise<span class="signature">(moduleName)</span><span class="type-signature"> &rarr; {Promise}</span></h4> </dt> <dd> <div class="description"> Creates Promise for module. It will be resolved as soon as module is being loaded from server. </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>moduleName</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of module for which Promise should be created.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line159">line 159</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise, which will be resolved as soon as the requested module is being loaded. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> </dd> <dt> <h4 class="name" id="_filterNotRequestedModules"><span class="type-signature">&lt;protected> </span>_filterNotRequestedModules<span class="signature">(modules)</span><span class="type-signature"> &rarr; {array}</span></h4> </dt> <dd> <div class="description"> Filters a list of modules and returns only these which have been not yet requested for delivery via network. </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>modules</code></td> <td class="type"> <span class="param-type">array</span> </td> <td class="description last">List of modules which which will be filtered.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line255">line 255</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> List of modules not yet requested for delivery via network. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">array</span> </dd> </dl> </dd> <dt> <h4 class="name" id="_getConfigParser"><span class="type-signature">&lt;protected> </span>_getConfigParser<span class="signature">()</span><span class="type-signature"> &rarr; {<a href="ConfigParser.html">ConfigParser</a>}</span></h4> </dt> <dd> <div class="description"> Returns instance of <a href="ConfigParser.html">ConfigParser</a> class currently used. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line186">line 186</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Instance of <a href="ConfigParser.html">ConfigParser</a> class. </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="ConfigParser.html">ConfigParser</a></span> </dd> </dl> </dd> <dt> <h4 class="name" id="_getDependencyBuilder"><span class="type-signature">&lt;protected> </span>_getDependencyBuilder<span class="signature">()</span><span class="type-signature"> &rarr; {<a href="DependencyBuilder.html">DependencyBuilder</a>}</span></h4> </dt> <dd> <div class="description"> Returns instance of <a href="DependencyBuilder.html">DependencyBuilder</a> class currently used. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line202">line 202</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Instance of <a href="DependencyBuilder.html">DependencyBuilder</a> class. </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="DependencyBuilder.html">DependencyBuilder</a></span> </dd> </dl> </dd> <dt> <h4 class="name" id="_getModuleImplementations"><span class="type-signature">&lt;protected> </span>_getModuleImplementations<span class="signature">(requiredModules)</span><span class="type-signature"> &rarr; {array}</span></h4> </dt> <dd> <div class="description"> Retrieves module implementations to an array. </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>requiredModules</code></td> <td class="type"> <span class="param-type">array</span> </td> <td class="description last">Lit of modules, which implementations will be added to an array.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line218">line 218</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> List of modules implementations. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">array</span> </dd> </dl> </dd> <dt> <h4 class="name" id="_getURLBuilder"><span class="type-signature">&lt;protected> </span>_getURLBuilder<span class="signature">()</span><span class="type-signature"> &rarr; {<a href="URLBuilder.html">URLBuilder</a>}</span></h4> </dt> <dd> <div class="description"> Returns instance of <a href="URLBuilder.html">URLBuilder</a> class currently used. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line239">line 239</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Instance of <a href="URLBuilder.html">URLBuilder</a> class. </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="URLBuilder.html">URLBuilder</a></span> </dd> </dl> </dd> <dt> <h4 class="name" id="_loadModules"><span class="type-signature">&lt;protected> </span>_loadModules<span class="signature">(modules)</span><span class="type-signature"> &rarr; {Promise}</span></h4> </dt> <dd> <div class="description"> Loads list of modules. </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>modules</code></td> <td class="type"> <span class="param-type">array</span> </td> <td class="description last">List of modules to be loaded.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line280">line 280</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise, which will be resolved as soon as all module a being loaded. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> </dd> <dt> <h4 class="name" id="_loadScript"><span class="type-signature">&lt;protected> </span>_loadScript<span class="signature">(url)</span><span class="type-signature"> &rarr; {Promise}</span></h4> </dt> <dd> <div class="description"> Loads a &ltscript&gt element on the page. </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>url</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The src of the script.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line337">line 337</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise which will be resolved as soon as the script is being loaded. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> </dd> <dt> <h4 class="name" id="_resolveDependencies"><span class="type-signature">&lt;protected> </span>_resolveDependencies<span class="signature">(modules)</span><span class="type-signature"> &rarr; {Promise}</span></h4> </dt> <dd> <div class="description"> Resolves modules dependencies. </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>modules</code></td> <td class="type"> <span class="param-type">array</span> </td> <td class="description last">List of modules which dependencies should be resolved.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line373">line 373</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise which will be resolved as soon as all dependencies are being resolved. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> </dd> <dt> <h4 class="name" id="_setModuleImplementation"><span class="type-signature">&lt;protected> </span>_setModuleImplementation<span class="signature">(modules)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Invokes the implementation method of list of modules passing the implementations of its dependencies. </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>modules</code></td> <td class="type"> <span class="param-type">array</span> </td> <td class="description last">List of modules to which implementation should be set.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line404">line 404</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="_waitForModule"><span class="type-signature">&lt;protected> </span>_waitForModule<span class="signature">(module)</span><span class="type-signature"> &rarr; {Promise}</span></h4> </dt> <dd> <div class="description"> Resolves a Promise as soon as all module dependencies are being resolved or it has implementation already. </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>module</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last">The module for which this function should wait.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line463">line 463</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> </dd> <dt> <h4 class="name" id="_waitForModules"><span class="type-signature">&lt;protected> </span>_waitForModules<span class="signature">(modules)</span><span class="type-signature"> &rarr; {Promise}</span></h4> </dt> <dd> <div class="description"> Resolves a Promise as soon as all dependencies of all provided modules are being resolved and modules have implementations. </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>modules</code></td> <td class="type"> <span class="param-type">array</span> </td> <td class="description last">List of modules for which implementations this function should wait.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line488">line 488</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> </dd> <dt> <h4 class="name" id="define"><span class="type-signature"></span>define<span class="signature">(name, dependencies, implementation, <span class="optional">config</span>)</span><span class="type-signature"> &rarr; {Object}</span></h4> </dt> <dd> <div class="description"> Defines a module in the system and fires <a href="Loader.html#event:moduleRegister">Loader#event:moduleRegister</a> event with the registered module as param. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Argument</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="attributes"> </td> <td class="description last">The name of the module.</td> </tr> <tr> <td class="name"><code>dependencies</code></td> <td class="type"> <span class="param-type">array</span> </td> <td class="attributes"> </td> <td class="description last">List of module dependencies.</td> </tr> <tr> <td class="name"><code>implementation</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> </td> <td class="description last">The implementation of the module.</td> </tr> <tr> <td class="name"><code>config</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">Object configuration: <ul> <strong>Optional properties</strong>: <li>path (String) - Explicitly set path of the module. If omitted, module name will be used as path</li> <li>condition (Object) Object which represents if the module should be added automatically after another module. It should have the following properties:</li> <ul> <li>trigger - the module, which should trigger the loading of the current module</li> <li>test - function, which should return true if module should be loaded</li> </ul> </ul></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line41">line 41</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> The constructed module. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> </dd> <dt> <h4 class="name" id="emit"><span class="type-signature"></span>emit<span class="signature">(event, args)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Emits an event. The function calls all registered listeners in the order they have been added. The provided args param will be passed to each listener of the 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">string</span> </td> <td class="description last">The name of the event.</td> </tr> <tr> <td class="name"><code>args</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last">Object, which will be passed to the listener as only argument.</td> </tr> </tbody> </table> <dl class="details"> <dt class="inherited-from">Inherited From:</dt> <dd class="inherited-from"><ul class="dummy"><li> <a href="EventEmitter.html#emit">EventEmitter#emit</a> </li></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="event-emitter.js.html">event-emitter.js</a>, <a href="event-emitter.js.html#line57">line 57</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="getConditionalModules"><span class="type-signature"></span>getConditionalModules<span class="signature">()</span><span class="type-signature"> &rarr; {array}</span></h4> </dt> <dd> <div class="description"> Returns list of currently registered conditional modules. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line69">line 69</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> List of currently registered conditional modules. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">array</span> </dd> </dl> </dd> <dt> <h4 class="name" id="getModules"><span class="type-signature"></span>getModules<span class="signature">()</span><span class="type-signature"> &rarr; {array}</span></h4> </dt> <dd> <div class="description"> Returns list of currently registered modules. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line79">line 79</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> List of currently registered modules. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">array</span> </dd> </dl> </dd> <dt> <h4 class="name" id="off"><span class="type-signature"></span>off<span class="signature">(event, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Removes an event from the list of event listeners to some 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">string</span> </td> <td class="description last">The name of the event.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback method to be removed from the list of listeners.</td> </tr> </tbody> </table> <dl class="details"> <dt class="inherited-from">Inherited From:</dt> <dd class="inherited-from"><ul class="dummy"><li> <a href="EventEmitter.html#off">EventEmitter#off</a> </li></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="event-emitter.js.html">event-emitter.js</a>, <a href="event-emitter.js.html#line34">line 34</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="on"><span class="type-signature"></span>on<span class="signature">(event, callback)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Adds event listener to an 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">string</span> </td> <td class="description last">The name of the event.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback method to be invoked when event is being emitted.</td> </tr> </tbody> </table> <dl class="details"> <dt class="inherited-from">Inherited From:</dt> <dd class="inherited-from"><ul class="dummy"><li> <a href="EventEmitter.html#on">EventEmitter#on</a> </li></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="event-emitter.js.html">event-emitter.js</a>, <a href="event-emitter.js.html#line22">line 22</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="require"><span class="type-signature"></span>require<span class="signature">(modules, success, failure)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Requires list of modules. If a module is not yet registered, it will be ignored and its implementation in the provided success callback will be left undefined.<br> </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>modules</code></td> <td class="type"> <span class="param-type">array</span> | <span class="param-type">Array.&lt;string></span> </td> <td class="description last">Modules can be specified as an array of strings or provided as multiple string parameters.</td> </tr> <tr> <td class="name"><code>success</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback, which will be invoked in case of success. The provided parameters will be implementations of all required modules.</td> </tr> <tr> <td class="name"><code>failure</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">Callback, which will be invoked in case of failure. One parameter with information about the error will be provided.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line95">line 95</a> </li></ul></dd> </dl> </dd> </dl> <h3 class="subsection-title">Events</h3> <dl> <dt> <h4 class="name" id="event:moduleRegister">moduleRegister</h4> </dt> <dd> <div class="description"> Indicates that a module has been registered. </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>module</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last">The registered module.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="script-loader.js.html">script-loader.js</a>, <a href="script-loader.js.html#line514">line 514</a> </li></ul></dd> </dl> </dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="ConfigParser.html">ConfigParser</a></li><li><a href="DependencyBuilder.html">DependencyBuilder</a></li><li><a href="EventEmitter.html">EventEmitter</a></li><li><a href="Loader.html">Loader</a></li><li><a href="URLBuilder.html">URLBuilder</a></li></ul><h3>Events</h3><ul><li><a href="Loader.html#event:moduleRegister">moduleRegister</a></li></ul> </nav> <br clear="both"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha5</a> on Tue Jun 16 2015 17:51:36 GMT+0200 (CEST) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>