Skip to content

Common API

All modules have the following common API.

init()

Asynchronous method that resolves when the modules finishes its initialization.

Although loadModule returns the module already initialized, this method is maintained for compatibility purposes.

Output:

  • promise (Promise): Promise that is resolved when the module is initialized. The promise returns the module.

Example:

1
2
3
module.init(function(mod) {
    console.log("module initialized");
});

getModuleName()

Returns the name identifier of the module.

Output:

  • name (string): Module name

Example:

1
2
3
4
5
6
import { loadModule } from "@3ddv/dvm";

loadModule("module_name", {...})
    .then(function(module) {
        console.log(module.getModuleName()) // "module_name"
    });

getModuleVersion()

Returns the module version.

Output:

  • version (string): module version

Example:

var version = module.getModuleVersion();

getPluginsList()

Returns a list with the current plugins in use (if any).

Output:

  • plugins (string[]): Plugins list.

Example:

var list = module.getPluginsList();

getClientId()

Returns the client id used in this instance (if any).

Output:

  • client_id (string | null): client id

Example:

var client_id = module.getClientId();

getModuleId()

Static Badge Static Badge

Returns the unique per-instance id of the module. Use it to look the instance back up through the registry (see Lifecycle).

Output:

  • module_id (string): unique per-instance id.

Example:

var id = module.getModuleId();

destroy()

Static Badge Static Badge

Asynchronous method that permanently destroys the module and releases every resource it holds. Calling it again is safe and does nothing, and the instance must not be used afterward. See Lifecycle for the create/destroy pattern.

Output:

  • promise (Promise): resolves once the module is destroyed.

Example:

await module.destroy();

isDestroyed()

Static Badge Static Badge

Returns true once destroy() has been called on the instance.

Output:

  • destroyed (boolean): true if destroy() has been called.

Example:

1
2
3
if (!module.isDestroyed()) {
    // safe to use
}

Module registry

Static Badge Static Badge

The module manager exposes synchronous queries over the modules that are currently live, registered on construction and removed once their destroy() resolves. Import them from @3ddv/dvm (or @3ddv/dvm-internal), not from a module instance. See Lifecycle for the create/destroy pattern.

getModules()

Returns every top-level module currently live in the registry. Synchronous.

Output:

  • modules (Module[]): the live top-level modules (empty array when none are loaded).

Example:

1
2
3
import { getModules } from "@3ddv/dvm";

getModules(); // returns [ map_viewer instance, 3d_viewer instance, ... ]

getModuleById()

Looks up a single live module by its per-instance id (the value returned by getModuleId()). Synchronous.

Input:

  • module_id (string): the per-instance module id to resolve.

Output:

  • module (Module | undefined): the matching module, or undefined if no live module has that id.

Example:

1
2
3
import { getModuleById } from "@3ddv/dvm";

getModuleById(module.getModuleId()); // returns the module, or undefined once destroyed

getModulesByType()

Returns every live module of a given type, e.g. "map_viewer" or "3d_viewer". Synchronous.

Input:

  • module_type (string): the module type to filter by.

Output:

  • modules (Module[]): the live modules of that type (empty array when none match).

Example:

1
2
3
import { getModulesByType } from "@3ddv/dvm";

getModulesByType("3d_viewer"); // returns [ 3d_viewer instance, ... ]