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 : string
The id of the module to load.
d : goog.async.Deferred
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 : string
Identifier of the module.
code »
afterLoadModuleCode(id)
Method called just after module code is loaded
Arguments:
id : string
Identifier of the module.
code »
beforeLoadModuleCode(id)
Method called just before a module code is loaded.
Arguments:
id : string
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
The reason for the failure.
code »
disposeInternal()
No description.
code »
execOnLoad(moduleIdfnopt_handleropt_noLoadopt_userInitiatedopt_preferSynchronous) goog.module.ModuleLoadCallback
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 : 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.
code »
executeCallbacks_(type)
Call the callback functions of the specified type.
Arguments:
type : goog.module.ModuleManager.CallbackType
The callback type.
code »
getBackOff_() number
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: number  Delay, in ms.
code »
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.
code »
getModuleContext() Object
Gets the module context to use to initialize the module.
Returns: Object  The context.
code »
getModuleInfo(id) goog.module.ModuleInfo
Gets a module info object by id.
Arguments:
id : string
A module identifier.
Returns: goog.module.ModuleInfo  The module info.
code »
getNotYetLoadedTransitiveDepIds_(id) !Array.<string>
Builds a list of the ids of the not-yet-loaded modules that a particular module transitively depends on, including itself.
Arguments:
id : string
The id of a not-yet-loaded module.
Returns: !Array.<string>  An array of module ids in dependency order that's guaranteed to end with the provided module id.
code »
handleLoadError_(requestedLoadingModuleIdsrequestedModuleIdsWithDepsstatus)
Handles a module load failure.
Arguments:
requestedLoadingModuleIds : !Array.<string>
Modules ids that were requested in failed request. Does not included calculated dependencies.
requestedModuleIdsWithDeps : !Array.<string>
All module ids requested in the failed request including all dependencies.
status : ?number
The error status.
code »
handleLoadTimeout_()
Handles a module load timeout.
code »
isActive() boolean
Determines if the ModuleManager is active
Returns: boolean  TRUE iff the ModuleManager is active (i.e., not idle).
code »
isModuleLoading(id) boolean
Gets whether a module is currently loading or in the queue, waiting to be loaded.
Arguments:
id : string
A module id.
Returns: boolean  TRUE iff the module is loading.
code »
isUserActive() boolean
Determines if the ModuleManager is user active
Returns: boolean  TRUE iff the ModuleManager is user active (i.e., not idle).
code »
load(moduleIdopt_userInitiated) goog.async.Deferred
Loads a module, returning a goog.async.Deferred for keeping track of the result.
Arguments:
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.
code »
loadModulesOrEnqueueIfNotLoadedOrLoading_(idsopt_userInitiated) !Object.<string, !goog.async.Deferred>
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>
The id of the module to load.
opt_userInitiated : boolean=
If the load is a result of a user action.
Returns: !Object.<string, !goog.async.Deferred>  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>
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>
The ids of the modules to load.
opt_isRetry : boolean=
If the load is a retry of a previous load attempt.
opt_forceReload : boolean=
Whether to bypass cache while loading the module.
code »
loadMultiple(moduleIdsopt_userInitiated) !Object.<string, !goog.async.Deferred>
Loads a list of modules, returning a goog.async.Deferred for keeping track of the result.
Arguments:
moduleIds : Array.<string>
A list of module ids.
opt_userInitiated : boolean=
If the load is a result of a user action.
Returns: !Object.<string, !goog.async.Deferred>  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 : string
The id of the module to prefetch.
code »
preloadModule(idopt_timeout) !goog.async.Deferred
Preloads a module after a short delay.
Arguments:
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.
code »
processModulesForLoad_(ids) !Array.<string>
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>
The ids that need to be loaded.
Returns: !Array.<string>  The ids to load, including dependencies.
code »
registerCallback(typesfn)
The function to call if the module manager is in error.
Arguments:
types : goog.module.ModuleManager.CallbackType | Array.<goog.module.ModuleManager.CallbackType>
The callback type.
fn : Function
The function to register as a callback.
code »
registerCallback_(typefn)
Register a callback for the specified callback type.
Arguments:
type : goog.module.ModuleManager.CallbackType
The callback type.
fn : Function
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
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.
code »
registerLateInitializationCallback(fnopt_handler)
Register a late initialization callback for the currently loading module. Callbacks registered via this function are executed similar to , but they are fired after all initialization callbacks are called.
Arguments:
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.
code »
registerModuleLoadCallbacks_(idmoduleInfouserInitiatedd)
Registers the callbacks and handles logic if it is a user initiated module load.
Arguments:
id : string
The id of the module to possibly load.
moduleInfo : !goog.module.ModuleInfo
The module identifier for the given id.
userInitiated : boolean
If the load was user initiated.
d : goog.async.Deferred
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
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>>
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=
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.
code »
setBatchModeEnabled(enabled)
Sets the batch mode as enabled or disabled for the module manager.
Arguments:
enabled : boolean
Whether the batch mode is to be enabled or not.
code »
setConcurrentLoadingEnabled(enabled)
Sets the concurrent loading mode as enabled or disabled for the module manager. Requires a moduleloader implementation that supports concurrent loads. The default does not.
Arguments:
enabled : boolean
No description.
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 : string
A module id.
code »
setLoader(loader)
Sets the application-specific module loader.
Arguments:
loader : goog.module.AbstractModuleLoader
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 .
Arguments:
fn : Function
The constructor function.
code »
setModuleContext(context)
Sets the module context to use to initialize the module.
Arguments:
context : Object
The context.
code »
setModuleUris(moduleUriMap)
Sets the module uris.
Arguments:
moduleUriMap : Object
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=
An optional scope to call the callback in.
code »
dispose() void
Disposes of the object. If the object hasn'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: void  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' disposeInternal method. Everywhere else the public dispose method must be used. For example:
  mypackage.MyClass = function() {
    mypackage.MyClass.base(this, 'constructor');
    // Constructor logic specific to MyClass.
    ...
  };
  goog.inherits(mypackage.MyClass, goog.Disposable);

  mypackage.MyClass.prototype.disposeInternal = function() {
    // Dispose logic specific to MyClass.
    ...
    // Call superclass's disposeInternal at the end of the subclass's, like
    // in C++, to avoid hard-to-catch issues.
    mypackage.MyClass.base(this, 'disposeInternal');
  };
code »
getDisposed() boolean
Use #isDisposed instead. No description.
Returns: boolean  Whether the object has been disposed of.
code »
isDisposed() boolean
No description.
Returns: boolean  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 : goog.disposable.IDisposable
that will be disposed when this object is disposed.
code »

Instance Properties

baseModuleInfo_ : goog.module.ModuleInfo
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_ :
A map of callback types to the functions to call for the specified callback type.
Code »
concurrentLoadingEnabled_ :
Whether the module requests may be sent out of order.
Code »
consecutiveFailures_ :
The number of consecutive failures that have happened upon module load requests.
Code »
constructor :
No description.
Code »
currentlyLoadingModule_ : goog.module.ModuleInfo
The module that is currently loading, or null if not loading anything.
Code »
initialModulesLoaded_ : goog.async.Deferred
Deferred for when all initial modules have loaded. We currently block sending additional module requests until this deferred resolves. In a future optimization it may be possible to use the initial modules as seeds for the module loader "requested module ids" and start making new requests even sooner.
Code »
lastActive_ :
Determines if the module manager was just active before the processing of the last data.
Code »
lastInitialModuleId_ :
The id of the last requested initial module. When it loaded the deferred in this.initialModulesLoaded_ resolves.
Code »
loadTracer_ :
Tracer that measures how long it takes to load a module.
Code »
A loader for the modules that implements loadModules(ids, moduleInfoMap, opt_successFn, opt_errorFn, opt_timeoutFn, opt_forceReload) method.
Code »
loadingModuleIds_ :
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_ : goog.debug.Logger
A logger.
Code »
moduleContext_ :
The module context needed for module initialization.
Code »
moduleInfoMap_ :
A mapping from module id to ModuleInfo object.
Code »
requestedLoadingModuleIds_ :
The requested ids of the currently loading modules. This does not include module dependencies that may also be loading.
Code »
requestedModuleIdsQueue_ :
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 »
requestedModuleIds_ :
All module ids that have ever been requested. In concurrent loading these are the ones to subtract from future requests.
Code »
userInitiatedLoadingModuleIds_ :
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 »
disposed_ :
Whether the object has been disposed of.
Code »
onDisposeCallbacks_ :
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 »
goog.module.ModuleManager.instance_ :
No description.
Code »
goog.module.ModuleManager.superClass_ :
No description.
Code »

Enumerations

goog.module.ModuleManager.CallbackType :
The type of callbacks that can be registered with the module manager,.
Constants:
ACTIVE
No description.
ERROR
No description.
IDLE
No description.
USER_ACTIVE
No description.
USER_IDLE
No description.
Code »
goog.module.ModuleManager.FailureType :
The possible reasons for a module load failure callback being fired.
Constants:
CONSECUTIVE_FAILURES
No description.
INIT_ERROR
No description.
OLD_CODE_GONE
No description.
TIMEOUT
No description.
UNAUTHORIZED
No description.
Code »

Package module

Package Reference