The goog.module.ModuleManager Class

goog.module.ModuleManager
> goog.Disposable

goog.module.ModuleManager()

The ModuleManager keeps track of all modules in the environment. Since modules may not have their code loaded, we must keep track of them.

.CORRUPT_RESPONSE_STATUS_CODE {number}

A non-HTTP status code indicating a corruption in loaded module. This should be used by a ModuleLoader as a replacement for the HTTP code given to the error handler function to indicated that the module was corrupted. This will set the forceReload flag on the loadModules method when retrying module loading.

The goog.module.ModuleManager.CallbackType Enum

The type of callbacks that can be registered with the module manager,. … more

The goog.module.ModuleManager.FailureType Enum

The possible reasons for a module load failure callback being fired. … more

.addOnDisposeCallback(callback, opt_scope)

Inherited from goog.Disposable .

Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.

callback {!Function}
The callback function.
opt_scope {Object=}
An optional scope to call the callback in.

.afterLoadModuleCode(id)

Method called just after module code is loaded

id {string}
Identifier of the module.

.beforeLoadModuleCode(id)

Method called just before a module code is loaded.

id {string}
Identifier of the module.

.creationStack {string}

Inherited from goog.Disposable .

If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.

.dispose()

Inherited from goog.Disposable .

Disposes of the object. If the object hasn't already been disposed of, calls {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should override {@link #disposeInternal} in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.

returns {void}
Nothing.

.execOnLoad(moduleId, fn, opt_handler, opt_noLoad, opt_userInitiated, opt_preferSynchronous)

Requests that a function be called once a particular module is loaded. Client code can use this method to safely call into modules that may not yet be loaded. For consistency, this method always calls the function asynchronously -- even if the module is already loaded. Initiates loading of the module if necessary, unless opt_noLoad is true.

moduleId {string}
A module id.
fn {Function}
Function to execute when the module has loaded.
opt_handler {Object=}
Optional handler under whose scope to execute the callback.
opt_noLoad {boolean=}
TRUE iff not to initiate loading of the module.
opt_userInitiated {boolean=}
TRUE iff the loading of the module was user initiated.
opt_preferSynchronous {boolean=}
TRUE iff the function should be executed synchronously if the module has already been loaded.
returns {goog.module.ModuleLoadCallback}
A callback wrapper that exposes an abort and execute method.

.getLoader()

Gets the application-specific module loader.

returns {goog.module.AbstractModuleLoader}
An object that has a loadModules(ids, moduleInfoMap, opt_successFn, opt_errFn, opt_timeoutFn, opt_forceReload) method.

.getModuleContext()

Gets the module context to use to initialize the module.

returns {Object}
The context.

.getModuleInfo(id)

Gets a module info object by id.

id {string}
A module identifier.
returns {goog.module.ModuleInfo}
The module info.

.isActive()

Determines if the ModuleManager is active

returns {boolean}
TRUE iff the ModuleManager is active (i.e., not idle).

.isDisposed()

Inherited from goog.Disposable .

returns {boolean}
Whether the object has been disposed of.

.isModuleLoading(id)

Gets whether a module is currently loading or in the queue, waiting to be loaded.

id {string}
A module id.
returns {boolean}
TRUE iff the module is loading.

.isUserActive()

Determines if the ModuleManager is user active

returns {boolean}
TRUE iff the ModuleManager is user active (i.e., not idle).

.load(moduleId, opt_userInitiated)

Loads a module, returning a goog.async.Deferred for keeping track of the result.

moduleId {string}
A module id.
opt_userInitiated {boolean=}
If the load is a result of a user action.
returns {goog.async.Deferred}
A deferred object.

.loadMultiple(moduleIds, opt_userInitiated)

Loads a list of modules, returning a goog.async.Deferred for keeping track of the result.

moduleIds {Array.<string>}
A list of module ids.
opt_userInitiated {boolean=}
If the load is a result of a user action.
returns {Object.<!goog.async.Deferred>}
A mapping from id (String) to deferred objects that will callback or errback when the load for that id is finished.

.prefetchModule(id)

Prefetches a JavaScript module and its dependencies, which means that the module will be downloaded, but not evaluated. To complete the module load, the caller should also call load or execOnLoad after prefetching the module.

id {string}
The id of the module to prefetch.

.preloadModule(id, opt_timeout)

Preloads a module after a short delay.

id {string}
The id of the module to preload.
opt_timeout {number=}
The number of ms to wait before adding the module id to the loading queue (defaults to 0 ms). Note that the module will be loaded asynchronously regardless of the value of this parameter.
returns {goog.async.Deferred}
A deferred object.

.registerCallback(types, fn)

The function to call if the module manager is in error.

types {goog.module.ModuleManager.CallbackType|Array.<goog.module.ModuleManager.CallbackType>}
The callback type.
fn {Function}
The function to register as a callback.

.registerDisposable(disposable)

Inherited from goog.Disposable .

Associates a disposable object with this object so that they will be disposed together.

disposable {goog.disposable.IDisposable}
that will be disposed when this object is disposed.

.registerInitializationCallback(fn, opt_handler)

Register an initialization callback for the currently loading module. This should only be called by script that is executed during the evaluation of a module's javascript. This is almost equivalent to calling the function inline, but ensures that all the code from the currently loading module has been loaded. This makes it cleaner and more robust than calling the function inline. If this function is called from the base module (the one that contains the module manager code), the callback is held until #setAllModuleInfo is called, or until #setModuleContext is called, whichever happens first.

fn {Function}
A callback function that takes a single argument which is the module context.
opt_handler {Object=}
Optional handler under whose scope to execute the callback.

.registerLateInitializationCallback(fn, opt_handler)

Register a late initialization callback for the currently loading module. Callbacks registered via this function are executed similar to {@see registerInitializationCallback}, but they are fired after all initialization callbacks are called.

fn {Function}
A callback function that takes a single argument which is the module context.
opt_handler {Object=}
Optional handler under whose scope to execute the callback.

.setAllModuleInfo(infoMap)

Sets the module info for all modules. Should only be called once.

infoMap {Object.<Array.<string>>}
An object that contains a mapping from module id (String) to list of required module ids (Array).

.setAllModuleInfoString(opt_info, opt_loadingModuleIds)

Sets the module info for all modules. Should only be called once. Also marks modules that are currently being loaded.

opt_info {string=}
A string representation of the module dependency graph, in the form: module1:dep1,dep2/module2:dep1,dep2 etc. Where depX is the base-36 encoded position of the dep in the module list.
opt_loadingModuleIds {Array.<string>=}
A list of moduleIds that are currently being loaded.

.setBatchModeEnabled(enabled)

Sets the batch mode as enabled or disabled for the module manager.

enabled {boolean}
Whether the batch mode is to be enabled or not.

.setLoaded(id)

Records that a module was loaded. Also initiates loading the next module if any module requests are queued. This method is called by code that is generated and appended to each dynamic module's code at compilation time.

id {string}
A module id.

.setLoader(loader)

Sets the application-specific module loader.

loader {goog.module.AbstractModuleLoader}
An object that has a loadModules(ids, moduleInfoMap, opt_successFn, opt_errFn, opt_timeoutFn, opt_forceReload) method.

.setModuleConstructor(fn)

Sets the constructor to use for the module object for the currently loading module. The constructor should derive from {@see goog.module.BaseModule}.

fn {Function}
The constructor function.

.setModuleContext(context)

Sets the module context to use to initialize the module.

context {Object}
The context.

.setModuleUris(moduleUriMap)

Sets the module uris.

moduleUriMap {Object}
The map of id/uris pairs for each module.