Lifecycle¶
A module instance (a map viewer or a 3D viewer) holds resources that are not released when you drop your reference to
it. When you are done with an instance, destroy it explicitly with destroy().
Destroying a module¶
destroy()¶
Asynchronous method that permanently destroys the module instance and releases every resource it holds.
- Asynchronous. Resolves once the module is destroyed and its resources released.
- Safe to call again. A second call does nothing.
- Single-use. Do not call anything else on the instance afterward.
Output:
promise(Promise): resolves once the module is destroyed.
Example:
Warning
This method is asynchronous, and the instance is unusable after it resolves.
isDestroyed()¶
Returns true once destroy() has been called on the instance. Use it to guard late-arriving callbacks or deferred work
that might run after the module is destroyed.
Output:
destroyed(boolean):trueifdestroy()has been called.
Example:
getModuleId()¶
Returns the unique per-instance id of the module. Use it to look the instance back up through the registry (below).
Output:
module_id(string): the unique per-instance id.
Example:
The live-module registry¶
The module manager keeps a registry of every module that is currently live, registered on construction and removed
automatically once its destroy() resolves. Query it through the functions exported from @3ddv/dvm (and
@3ddv/dvm-internal); all three are synchronous.
| Function | Returns | Notes |
|---|---|---|
getModules() |
Module[] |
Every top-level live module. |
getModuleById(id) |
Module \| undefined |
Single instance by its getModuleId() value. |
getModulesByType(type) |
Module[] |
Live modules of a type, e.g. "map_viewer". |
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:
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, orundefinedif no live module has that id.
Example:
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:
The registry only lists modules that are still live, so you can use it to destroy every module your application has open:
Warning
Destroy what you discard. The registry keeps every module alive until its destroy() resolves, so a module
discarded without destroy() leaks. Any code that creates and discards modules (route changes, component unmount,
venue swaps) must call destroy().
Create / destroy / reload pattern¶
To swap what a module shows, prefer the in-place loaders (loadMap / loadView3d): they reuse the same instance.
Go for destroy-and-recreate only when you are removing the module from the page entirely (e.g. a single-page-app
route leaving the view):
Further reading¶
- Common API: methods shared by every module, including
destroy(),isDestroyed(), andgetModuleId(). - map_viewer API: full reference for the map-viewer instance.
- 3d_viewer API: full reference for the 3d-viewer instance.