Skip to the main content


GlobalLoader

An AMD loader that installs modules into the global edx namespace.


GlobalLoader.defineAs(name, path)

Define a module that can be accessed globally in the edx namespace.

This function will typically be used in situations where UI Toolkit functionally is needed in code where RequireJS is not available. The module definition should be wrapped in boilerplate as follows:

;(function(define) {
    'use strict';
    define([...], function(...) {
        ...
    });
}).call(
    this,
    // Pick a define function as follows:
    // 1. Use the default 'define' function if it is available
    // 2. If not, use 'RequireJS.define' if that is available
    // 3. else use the GlobalLoader to install the class into the edx namespace
    typeof define === 'function' && define.amd ? define :
        (typeof RequireJS !== 'undefined' ? RequireJS.define :
            edx.GlobalLoader.defineAs('ModuleName', 'PATH/TO/MODULE'))
);

Parameters

name: string, The name by which the module will be accessed.

path: string, The module’s path.

Returns: function, A function that will create the module.

GlobalLoader.clear()

Clears all registered modules.

Note: this function is only provided for unit testing.