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

Inheritance

Constructor

goog.module.ModuleManager()

Instance Methods

Public Protected Private
addLoadModule_(idd)
Loads a single module for use with a given deferred.
Arguments:
id :
The id of the module to load.
d :
A deferred object.
code »
addUserInitiatedLoadingModule_(id)
Ensures that the module with the given id is listed as a user-initiated module that is being loaded. This method guarantees that a module will never get listed more than once.
Arguments:
id :
Identifier of the module.
code »
afterLoadModuleCode(id)
Method called just after module code is loaded
Arguments:
id :
Identifier of the module.
code »
beforeLoadModuleCode(id)
Method called just before a module code is loaded.
Arguments:
id :
Identifier of the module.
code »
dispatchActiveIdleChangeIfNeeded_()
Dispatches an ACTIVE or IDLE event if necessary.
code »
dispatchModuleLoadFailed_(cause)
Handles when a module load failed.
Arguments:
cause :
goog.module.ModuleManager.FailureType.<number>
The reason for the failure.
code »
disposeInternal()
No description.
code »
execOnLoad(moduleIdfnopt_handleropt_noLoadopt_userInitiatedopt_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.
Arguments:
moduleId :
A module id.
fn :
(Function | null)
Function to execute when the module has loaded.
opt_handler :
(Object | null | undefined)
Optional handler under whose scope to execute the callback.
opt_noLoad :
(boolean | undefined)
TRUE iff not to initiate loading of the module.
opt_userInitiated :
(boolean | undefined)
TRUE iff the loading of the module was user initiated.
opt_preferSynchronous :
(boolean | undefined)
TRUE iff the function should be executed synchronously if the module has already been loaded.
Returns:   A callback wrapper that exposes an abort and execute method.
code »
executeCallbacks_(type)
Call the callback functions of the specified type.
Arguments:
type :
goog.module.ModuleManager.CallbackType.<string>
The callback type.
code »
getBackOff_()
Gets the amount of delay to wait before sending a request for more modules. If a certain module request fails, we backoff a little bit and try again.
Returns:   Delay, in ms.
code »
getLoader()
Gets the application-specific module loader.
Returns:   An object that has a loadModules(ids, moduleInfoMap, opt_successFn, opt_errFn, opt_timeoutFn, opt_forceReload) method.
code »
getModuleContext()
(Object | null)
Gets the module context to use to initialize the module.
Returns: 
(Object | null)
  The context.
code »
getModuleInfo(id)
Gets a module info object by id.
Arguments:
id :
A module identifier.
Returns:   The module info.
code »
getNotYetLoadedTransitiveDepIds_(id)
(Array.<string> | null)
Builds a list of the ids of the not-yet-loaded modules that a particular module transitively depends on, including itself.
Arguments:
id :
The id of a not-yet-loaded module.
Returns: 
(Array.<string> | null)
  An array of module ids in dependency order that's guaranteed to end with the provided module id.
code »
handleLoadError_(status)
Handles a module load failure.
Arguments:
status :
(null | number)
The error status.
code »
handleLoadTimeout_()
Handles a module load timeout.
code »
isActive()
Determines if the ModuleManager is active
Returns:   TRUE iff the ModuleManager is active (i.e., not idle).
code »
isModuleLoading(id)
Gets whether a module is currently loading or in the queue, waiting to be loaded.
Arguments:
id :
A module id.
Returns:   TRUE iff the module is loading.
code »
isUserActive()
Determines if the ModuleManager is user active
Returns:   TRUE iff the ModuleManager is user active (i.e., not idle).
code »
load(moduleIdopt_userInitiated)
Loads a module, returning a goog.async.Deferred for keeping track of the result.
Arguments:
moduleId :
A module id.
opt_userInitiated :
(boolean | undefined)
If the load is a result of a user action.
Returns:   A deferred object.
code »
loadModulesOrEnqueueIfNotLoadedOrLoading_(idsopt_userInitiated)
Loads a list of modules or, if some other module is currently being loaded, appends the ids to the queue of requested module ids. Registers callbacks a module that is currently loading and returns a fired deferred for a module that is already loaded.
Arguments:
ids :
(Array.<string> | null)
The id of the module to load.
opt_userInitiated :
(boolean | undefined)
If the load is a result of a user action.
Returns:   A mapping from id (String) to deferred objects that will callback or errback when the load for that id is finished.
code »
loadModulesOrEnqueue_(ids)
Initiates loading of a list of modules or, if a module is currently being loaded, appends the modules to the queue of requested module ids. The caller should verify that the requested modules are not already loaded or loading. #loadModulesOrEnqueueIfNotLoadedOrLoading_ is a more lenient alternative to this method.
Arguments:
ids :
(Array.<string> | null)
The ids of the modules to load.
code »
loadModules_(idsopt_isRetryopt_forceReload)
Loads a list of modules and any of their not-yet-loaded prerequisites. If batch mode is enabled, the prerequisites will be loaded together with the requested modules and all requested modules will be loaded at the same time. The caller should verify that the requested modules are not already loaded and that no modules are currently loading before calling this method.
Arguments:
ids :
(Array.<string> | null)
The ids of the modules to load.
opt_isRetry :
(boolean | undefined)
If the load is a retry of a previous load attempt.
opt_forceReload :
(boolean | undefined)
Whether to bypass cache while loading the module.
code »
loadMultiple(moduleIdsopt_userInitiated)
Loads a list of modules, returning a goog.async.Deferred for keeping track of the result.
Arguments:
moduleIds :
(Array.<string> | null)
A list of module ids.
opt_userInitiated :
(boolean | undefined)
If the load is a result of a user action.
Returns:   A mapping from id (String) to deferred objects that will callback or errback when the load for that id is finished.
code »
loadNextModules_()
Loads the next modules on the queue.
code »
maybeFinishBaseLoad_()
If we are still loading the base module, consider the load complete.
code »
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.
Arguments:
id :
The id of the module to prefetch.
code »
preloadModule(idopt_timeout)
Preloads a module after a short delay.
Arguments:
id :
The id of the module to preload.
opt_timeout :
(number | undefined)
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:   A deferred object.
code »
processModulesForLoad_(ids)
(Array.<string> | null)
Processes a list of module ids for loading. Checks if any of the modules are already loaded and then gets transitive deps. Queues any necessary modules if batch mode is not enabled. Returns the list of ids that should be loaded.
Arguments:
ids :
(Array.<string> | null)
The ids that need to be loaded.
Returns: 
(Array.<string> | null)
  The ids to load, including dependencies.
code »
registerCallback(typesfn)
The function to call if the module manager is in error.
Arguments:
types :
(Array.<goog.module.ModuleManager.CallbackType.<string>> | goog.module.ModuleManager.CallbackType.<string> | null)
The callback type.
fn :
(Function | null)
The function to register as a callback.
code »
registerCallback_(typefn)
Register a callback for the specified callback type.
Arguments:
type :
goog.module.ModuleManager.CallbackType.<string>
The callback type.
fn :
(Function | null)
The callback function.
code »
registerInitializationCallback(fnopt_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.
Arguments:
fn :
(Function | null)
A callback function that takes a single argument which is the module context.
opt_handler :
(Object | null | undefined)
Optional handler under whose scope to execute the callback.
code »
registerLateInitializationCallback(fnopt_handler)
Register a late initialization callback for the currently loading module. Callbacks registered via this function are executed similar to registerInitializationCallback, but they are fired after all initialization callbacks are called.
Arguments:
fn :
(Function | null)
A callback function that takes a single argument which is the module context.
opt_handler :
(Object | null | undefined)
Optional handler under whose scope to execute the callback.
code »
registerModuleLoadCallbacks_(idmoduleInfouserInitiatedd)
Registers the callbacks and handles logic if it is a user initiated module load.
Arguments:
id :
The id of the module to possibly load.
moduleInfo :
The module identifier for the given id.
userInitiated :
If the load was user initiated.
d :
A deferred object.
code »
requeueBatchOrDispatchFailure_(cause)
Requeues batch loads that had more than one requested module (i.e. modules that were not included as dependencies) as separate loads or if there was only one requested module, fails that module with the received cause.
Arguments:
cause :
goog.module.ModuleManager.FailureType.<number>
The reason for the failure.
code »
setAllModuleInfo(infoMap)
Sets the module info for all modules. Should only be called once.
Arguments:
infoMap :
(Object.<(Array.<string> | null)> | null)
An object that contains a mapping from module id (String) to list of required module ids (Array).
code »
setAllModuleInfoString(opt_infoopt_loadingModuleIds)
Sets the module info for all modules. Should only be called once. Also marks modules that are currently being loaded.
Arguments:
opt_info :
(string | undefined)
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> | null | undefined)
A list of moduleIds that are currently being loaded.
code »
setBatchModeEnabled(enabled)
Sets the batch mode as enabled or disabled for the module manager.
Arguments:
enabled :
Whether the batch mode is to be enabled or not.
code »
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.
Arguments:
id :
A module id.
code »
setLoader(loader)
Sets the application-specific module loader.
Arguments:
loader :
An object that has a loadModules(ids, moduleInfoMap, opt_successFn, opt_errFn, opt_timeoutFn, opt_forceReload) method.
code »
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}.
Arguments:
fn :
(Function | null)
The constructor function.
code »
setModuleContext(context)
Sets the module context to use to initialize the module.
Arguments:
context :
(Object | null)
The context.
code »
setModuleUris(moduleUriMap)
Sets the module uris.
Arguments:
moduleUriMap :
(Object | null)
The map of id/uris pairs for each module.
code »
addOnDisposeCallback(callbackopt_scope)
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.
Arguments:
callback :
?function (this:T):
The callback function.
opt_scope :
(T | undefined)
An optional scope to call the callback in.
code »
dispose()
undefined
Disposes of the object. If the object hasn&amp;#39;t already been disposed of, calls #disposeInternal. Classes that extend goog.Disposable should override #disposeInternal in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.
Returns: 
undefined
  Nothing.
code »
disposeInternal()
Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend goog.Disposable should override this method. Not reentrant. To avoid calling it twice, it must only be called from the subclass&amp;#39; disposeInternal method. Everywhere else the public dispose method must be used. For example:
mypackage.MyClass = function() {
goog.base(this);
// Constructor logic specific to MyClass.
...
};
goog.inherits(mypackage.MyClass, goog.Disposable);

mypackage.MyClass.prototype.disposeInternal = function() {
// Dispose logic specific to MyClass.
...
// Call superclass&#39;s disposeInternal at the end of the subclass&#39;s, like
// in C++, to avoid hard-to-catch issues.
goog.base(this, &#39;disposeInternal&#39;);
};
code »
getDisposed()
Use #isDisposed instead. No description.
Returns:   Whether the object has been disposed of.
code »
isDisposed()
No description.
Returns:   Whether the object has been disposed of.
code »
registerDisposable(disposable)
Associates a disposable object with this object so that they will be disposed together.
Arguments:
disposable :
that will be disposed when this object is disposed.
code »

Instance Properties

baseModuleInfo_ :
Module info for the base module (the one that contains the module manager code), which we set as the loading module so one can register initialization callbacks in the base module. The base module is considered loaded when #setAllModuleInfo is called or #setModuleContext is called, whichever comes first.
Code »
batchModeEnabled_ :
Whether the batch mode (i.e. the loading of multiple modules with just one request) has been enabled.
Code »
callbackMap_ :
(Object | null)
A map of callback types to the functions to call for the specified callback type.
Code »
consecutiveFailures_ :
The number of consecutive failures that have happened upon module load requests.
Code »
currentlyLoadingModule_ :
The module that is currently loading, or null if not loading anything.
Code »
lastActive_ :
Determines if the module manager was just active before the processing of the last data.
Code »
loadTracer_ :
(null | number)
Tracer that measures how long it takes to load a module.
Code »
loader_ :
A loader for the modules that implements loadModules(ids, moduleInfoMap, opt_successFn, opt_errorFn, opt_timeoutFn, opt_forceReload) method.
Code »
loadingModuleIds_ :
(Array.<string> | null)
The ids of the currently loading modules. If batch mode is disabled, then this array will never contain more than one element at a time.
Code »
logger_ :
A logger.
Code »
moduleContext_ :
(Object | null)
The module context needed for module initialization.
Code »
moduleInfoMap_ :
(Object | null)
A mapping from module id to ModuleInfo object.
Code »
requestedLoadingModuleIds_ :
(Array.<string> | null)
The requested ids of the currently loading modules. This does not include module dependencies that may also be loading.
Code »
requestedModuleIdsQueue_ :
(Array.<(Array.<string> | null)> | null)
A queue of the ids of requested but not-yet-loaded modules. The zero position is the front of the queue. This is a 2-D array to group modules together with other modules that should be batch loaded with them, if batch loading is enabled.
Code »
userInitiatedLoadingModuleIds_ :
(Array.<string> | null)
The ids of the currently loading modules which have been initiated by user actions.
Code »
userLastActive_ :
Determines if the module manager was just user active before the processing of the last data. The module manager is user active if any of the user-initiated modules are loading or queued up to load.
Code »
creationStack :
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
Code »
dependentDisposables_ :
(Array.<(goog.disposable.IDisposable | null)> | null)
Disposables that should be disposed when this object is disposed.
Code »
disposed_ :
Whether the object has been disposed of.
Code »
onDisposeCallbacks_ :
(Array.<Function> | null)
Callbacks to invoke when this object is disposed.
Code »

Static Methods

goog.module.ModuleManager.getInstance()
No description.
code »

Static Properties

goog.module.ModuleManager.CORRUPT_RESPONSE_STATUS_CODE :
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.
Code »

Enumerations

goog.module.ModuleManager.CallbackType :
The type of callbacks that can be registered with the module manager,.
Constants:
ERROR
Fired when an error has occurred.
USER_ACTIVE
Fired when it becomes active and has user-initiated module loads to process.
USER_IDLE
Fired when it becomes idle and has no more user-initiated module loads to process.
ACTIVE
Fired when it becomes active and has module loads to process.
IDLE
Fired when it becomes idle and has no more module loads to process.
Code »
goog.module.ModuleManager.FailureType :
The possible reasons for a module load failure callback being fired.
Constants:
INIT_ERROR
The onLoad callbacks failed.
OLD_CODE_GONE
410 status, old code gone.
TIMEOUT
Request timeout.
CONSECUTIVE_FAILURES
Error status (not 401) returned multiple times.
UNAUTHORIZED
401 Status.
Code »

Package module

Package Reference