new Loader()
Creates an instance of Loader class.
- Source:
Extends
Methods
-
<protected> _createModulePromise(moduleName) → {Promise}
-
Creates Promise for module. It will be resolved as soon as module is being loaded from server.
Parameters:
Name Type Description moduleName
string The name of module for which Promise should be created. - Source:
Returns:
Promise, which will be resolved as soon as the requested module is being loaded.- Type
- Promise
-
<protected> _filterNotRequestedModules(modules) → {array}
-
Filters a list of modules and returns only these which have been not yet requested for delivery via network.
Parameters:
Name Type Description modules
array List of modules which which will be filtered. - Source:
Returns:
List of modules not yet requested for delivery via network.- Type
- array
-
<protected> _getConfigParser() → {ConfigParser}
-
Returns instance of ConfigParser class currently used.
- Source:
Returns:
Instance of ConfigParser class.- Type
- ConfigParser
-
<protected> _getDependencyBuilder() → {DependencyBuilder}
-
Returns instance of DependencyBuilder class currently used.
- Source:
Returns:
Instance of DependencyBuilder class.- Type
- DependencyBuilder
-
<protected> _getModuleImplementations(requiredModules) → {array}
-
Retrieves module implementations to an array.
Parameters:
Name Type Description requiredModules
array Lit of modules, which implementations will be added to an array. - Source:
Returns:
List of modules implementations.- Type
- array
-
<protected> _getURLBuilder() → {URLBuilder}
-
Returns instance of URLBuilder class currently used.
- Source:
Returns:
Instance of URLBuilder class.- Type
- URLBuilder
-
<protected> _loadModules(modules) → {Promise}
-
Loads list of modules.
Parameters:
Name Type Description modules
array List of modules to be loaded. - Source:
Returns:
Promise, which will be resolved as soon as all module a being loaded.- Type
- Promise
-
<protected> _loadScript(url) → {Promise}
-
Loads a <script> element on the page.
Parameters:
Name Type Description url
string The src of the script. - Source:
Returns:
Promise which will be resolved as soon as the script is being loaded.- Type
- Promise
-
<protected> _resolveDependencies(modules) → {Promise}
-
Resolves modules dependencies.
Parameters:
Name Type Description modules
array List of modules which dependencies should be resolved. - Source:
Returns:
Promise which will be resolved as soon as all dependencies are being resolved.- Type
- Promise
-
<protected> _setModuleImplementation(modules)
-
Invokes the implementation method of list of modules passing the implementations of its dependencies.
Parameters:
Name Type Description modules
array List of modules to which implementation should be set. - Source:
-
<protected> _waitForModule(module) → {Promise}
-
Resolves a Promise as soon as all module dependencies are being resolved or it has implementation already.
Parameters:
Name Type Description module
object The module for which this function should wait. - Source:
Returns:
- Type
- Promise
-
<protected> _waitForModules(modules) → {Promise}
-
Resolves a Promise as soon as all dependencies of all provided modules are being resolved and modules have implementations.
Parameters:
Name Type Description modules
array List of modules for which implementations this function should wait. - Source:
Returns:
- Type
- Promise
-
define(name, dependencies, implementation, config) → {Object}
-
Defines a module in the system and fires Loader#event:moduleRegister event with the registered module as param.
Parameters:
Name Type Argument Description name
string The name of the module. dependencies
array List of module dependencies. implementation
function The implementation of the module. config
object <optional>
Object configuration: -
Optional properties:
- path (String) - Explicitly set path of the module. If omitted, module name will be used as path
- condition (Object) Object which represents if the module should be added automatically after another module. It should have the following properties:
- trigger - the module, which should trigger the loading of the current module
- test - function, which should return true if module should be loaded
- Source:
Returns:
The constructed module.- Type
- Object
-
emit(event, args)
-
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.
Parameters:
Name Type Description event
string The name of the event. args
object Object, which will be passed to the listener as only argument. - Inherited From:
- Source:
-
getConditionalModules() → {array}
-
Returns list of currently registered conditional modules.
- Source:
Returns:
List of currently registered conditional modules.- Type
- array
-
getModules() → {array}
-
Returns list of currently registered modules.
- Source:
Returns:
List of currently registered modules.- Type
- array
-
off(event, callback)
-
Removes an event from the list of event listeners to some event.
Parameters:
Name Type Description event
string The name of the event. callback
function Callback method to be removed from the list of listeners. - Inherited From:
- Source:
-
on(event, callback)
-
Adds event listener to an event.
Parameters:
Name Type Description event
string The name of the event. callback
function Callback method to be invoked when event is being emitted. - Inherited From:
- Source:
-
require(modules, success, failure)
-
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.
Parameters:
Name Type Description modules
array | Array.<string> Modules can be specified as an array of strings or provided as multiple string parameters. success
function Callback, which will be invoked in case of success. The provided parameters will be implementations of all required modules. failure
function Callback, which will be invoked in case of failure. One parameter with information about the error will be provided. - Source:
Events
-
moduleRegister
-
Indicates that a module has been registered.
Parameters:
Name Type Description module
object The registered module. - Source: