DependencyLoader

core. DependencyLoader

Handles the loading of Adapt authoring tool module dependencies.

Constructor

new DependencyLoader(app)

Description:
  • Creates a new DependencyLoader instance
Source:
Parameters:
Name Type Description
app App The main app instance

Members

app :App

Description:
  • Reference to the main app
Source:
Reference to the main app
Type:
  • App

configs :Object.<string, Object>

Description:
  • Key/value store of all the Adapt dependencies' configs. Note this includes dependencies which are not loaded as Adapt modules (i.e. `module: false`).
Source:
Key/value store of all the Adapt dependencies' configs. Note this includes dependencies which are not loaded as Adapt modules (i.e. `module: false`).
Type:
  • Object.<string, Object>

configsLoadedHook :Hook

Description:
  • Hook called once all module configs are loaded
Source:
Hook called once all module configs are loaded
Type:
  • Hook

failedModules :Array.<string>

Description:
  • List of module names which have failed to load
Source:
List of module names which have failed to load
Type:
  • Array.<string>

instances :Object.<string, Object>

Description:
  • Map of module names to their loaded instances
Source:
Map of module names to their loaded instances
Type:
  • Object.<string, Object>

moduleLoadedHook :Hook

Description:
  • Hook for individual module load
Source:
Hook for individual module load
Type:
  • Hook

name :string

Description:
  • Name of the class (convenience function to stay consistent with other classes)
Source:
Name of the class (convenience function to stay consistent with other classes)
Type:
  • string

peerDependencies :Object.<string, Array.<string>>

Description:
  • Map of module names to arrays of modules that depend on them as peer dependencies
Source:
Map of module names to arrays of modules that depend on them as peer dependencies
Type:
  • Object.<string, Array.<string>>

Methods

getConfig(key) → {*|undefined}

Description:
  • Retrieves a configuration value from this module's config
Source:
Parameters:
Name Type Description
key string The configuration key to retrieve
Returns:
The configuration value if config is ready, undefined otherwise
Type
* | undefined

(async) load() → {Promise.<void>}

Description:
  • Loads all Adapt module dependencies. Essential modules are loaded first, then non-essential modules (with force mode).
Source:
Throws:
When any essential module fails to load
Type
Error
Returns:
Type
Promise.<void>

(async) loadConfigs() → {Promise.<void>}

Description:
  • Loads configuration files for all Adapt dependencies found in node_modules.
Source:
Returns:
Type
Promise.<void>

(async) loadModule(modName) → {Promise.<Object>}

Description:
  • Loads a single Adapt module by dynamically importing it, instantiating it, and waiting for its onReady promise. Should not need to be called directly.
Source:
Parameters:
Name Type Description
modName string Name of the module to load (e.g., 'adapt-authoring-core')
Throws:
When module already exists, is in an unknown format or cannot be initialised (or initialisation exceeds 60 second timeout)
Type
Error
Returns:
Resolves with module instance when module.onReady completes
Type
Promise.<Object>

(async) loadModuleConfig(modDir) → {Promise.<Object>}

Description:
  • Loads the relevant configuration files for an Adapt module by reading and merging package.json and adapt.json
Source:
Parameters:
Name Type Description
modDir string Absolute path to the module directory
Returns:
Resolves with configuration object
Type
Promise.<Object>

(async) loadModules(modules, optionsopt) → {Promise.<void>}

Description:
  • Loads a list of Adapt modules. Should not need to be called directly.
Source:
Parameters:
Name Type Attributes Description
modules Array.<string> Module names to load
options Object <optional>
Loading options
Properties
Name Type Attributes Default Description
force boolean <optional>
false If true, logs errors and continues loading other modules when a module fails. If false, throws a DependencyError on first failure.
Throws:
When a module fails to load and options.force is not true
Type
DependencyError
Returns:
Resolves when all modules have loaded (or failed to load in force mode)
Type
Promise.<void>

log(…args)

Description:
  • Logs a message using the app logger if available, otherwise falls back to console.log
Source:
Parameters:
Name Type Attributes Description
args * <repeatable>
Arguments to be logged

logError(…args)

Description:
  • Logs an error message using the app logger if available, otherwise falls back to console.log
Source:
Parameters:
Name Type Attributes Description
args * <repeatable>
Arguments to be logged

logProgress(instance)

Description:
  • Logs load progress
Source:
Parameters:
Name Type Description
instance AbstractModule The last loaded instance

(async) waitForModule(modName) → {Promise.<Object>}

Description:
  • Waits for a single module to load. Returns the instance (if loaded), or hooks into moduleLoadedHook to wait for it.
Source:
Parameters:
Name Type Description
modName string Name of module to wait for (accepts short names without 'adapt-authoring-' prefix)
Throws:
When module is missing from configs or has failed to load
Type
Error
Returns:
Resolves with module instance when module.onReady completes
Type
Promise.<Object>