Home

# Class 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.

extends goog.Disposable

Instance Method Summary
| `addLoadModule_(string id, ?goog.async.Deferred d)` Loads a single module for use with a given deferred.
| `addUserInitiatedLoadingModule_(string 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.
| `afterLoadModuleCode(string id)` Method called just after module code is loaded
| `beforeLoadModuleCode(string id)` Method called just before a module code is loaded.
| `dispatchActiveIdleChangeIfNeeded_()` Dispatches an ACTIVE or IDLE event if necessary.
| `dispatchModuleLoadFailed_(?goog.module.ModuleManager.FailureType cause)` Handles when a module load failed.

`disposeInternal()`

Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend {@code goog.Disposable} should override this method. Not reentrant. To avoid calling it twice, it must only be called from the subclass' {@code disposeInternal} method. Everywhere else the public {@code 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() {
    goog.base(this, 'disposeInternal');
    // Dispose logic specific to MyClass.
    ...
    };

`execOnLoad(string moduleId, ?Function fn, ?Object= opt_handler, boolean= opt_noLoad, boolean= opt_userInitiated, boolean= opt_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.

| `executeCallbacks_(?goog.module.ModuleManager.CallbackType type)` Call the callback functions of the specified type.
| `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.
| `getLoader() ⇒ ?goog.module.AbstractModuleLoader` Gets the application-specific module loader.
| `getModuleContext() ⇒ ?Object` Gets the module context to use to initialize the module.
| `getModuleInfo(string id) ⇒ ?goog.module.ModuleInfo` Gets a module info object by id.
| `getNotYetLoadedTransitiveDepIds_(string id) ⇒ ?Array.<string>` Builds a list of the ids of the not-yet-loaded modules that a particular module transitively depends on, including itself.
| `handleLoadError_(number status)` Handles a module load failure.
| `handleLoadTimeout_()` Handles a module load timeout.
| `isActive() ⇒ boolean` Determines if the ModuleManager is active
| `isModuleLoading(string id) ⇒ boolean` Gets whether a module is currently loading or in the queue, waiting to be loaded.
| `isUserActive() ⇒ boolean` Determines if the ModuleManager is user active
| `load(string moduleId, boolean= opt_userInitiated) ⇒ ?goog.async.Deferred` Loads a module, returning a goog.async.Deferred for keeping track of the result.
| `loadModulesOrEnqueueIfNotLoadedOrLoading_(?Array.<string> ids, boolean= opt_userInitiated) ⇒ ?Object` 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.
| `loadModulesOrEnqueue_(?Array.<string> 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. {@link #loadModulesOrEnqueueIfNotLoadedOrLoading_} is a more lenient alternative to this method.

`loadModules_(?Array.<string> ids, boolean= opt_isRetry, boolean= opt_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.

| `loadMultiple(?Array.<string> moduleIds, boolean= opt_userInitiated) ⇒ ?Object` Loads a list of modules, returning a goog.async.Deferred for keeping track of the result.
| `loadNextModules_(boolean= opt_noBatch)` Loads the next modules on the queue.
| `maybeFinishBaseLoad_()` If we are still loading the base module, consider the load complete.
| `maybeRequeueAndLoadNext_(?goog.module.ModuleManager.FailureType 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.
| `preloadModule(string id, number= opt_timeout) ⇒ ?goog.async.Deferred` Preloads a module after a short delay.
| `processModulesForLoad_(?Array.<string> 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.
| `registerCallback((Array|goog.module.ModuleManager.CallbackType|null) types, ?Function fn)` The function to call if the module manager is in error.
| `registerCallback_(?goog.module.ModuleManager.CallbackType type, ?Function fn)` Register a callback for the specified callback type.

`registerInitializationCallback(?Function fn, ?Object= 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.

| `registerModuleLoadCallbacks_(string id, !goog.module.ModuleInfo moduleInfo, boolean userInitiated, ?goog.async.Deferred d)` Registers the callbacks and handles logic if it is a user initiated module load.
| `setAllModuleInfo(?Object.<(Array.<string>|null)> infoMap)` Sets the module info for all modules. Should only be called once.
| `setAllModuleInfoString(string= opt_info, ?Array.<string>= opt_loadingModuleIds)` Sets the module info for all modules. Should only be called once. Also marks modules that are currently being loaded.
| `setBatchModeEnabled(boolean enabled)` Sets the batch mode as enabled or disabled for the module manager.
| `setLoaded(string 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.
| `setLoader(?goog.module.AbstractModuleLoader loader)` Sets the application-specific module loader.
| `setModuleConstructor(?Function fn)` Sets the constructor to use for the module object for the currently loading module. The constructor should derive from {@see goog.module.BaseModule}.
| `setModuleContext(?Object context)` Sets the module context to use to initialize the module.
| `setModuleUris(?Object moduleUriMap)` Sets the module uris.