Context module.

Modules intended to extend the context dynamically.

The module is a context entry that can be used to provide module instance and access its handle.

Usage example:

// Construct new module.
const myModule = new CxModule('my module', {
setup(setup) {
// Provide the values
setup.provide({ a: Foo, is: 'foo' });
},
});

// Load the module
const myModuleSupply = contextBuilder.provide(myModule);

// Start using the module
const myModuleUse = await context.get(myModule).use();

// Await for the module to load
await myModuleUse.whenReady;

// Access the value provided by module.
console.log(context.get(Foo));

// Stop using the module
myModuleUse.supply.off();

// Unload the module declaration.
myModuleSupply.off();

Hierarchy

  • CxModule

Implements

Constructors

Properties

[CxModule$Impl__symbol]: CxModule$Impl

Accessors

Methods

  • Sets up the module.

    This method is called when loading the module. It is used e.g. to provide more values for the context.

    By default:

    1. Satisfies module dependencies by setting them up.

      The dependency considered satisfied when it is settled.

    2. Initializes the module by initializing the dependencies.

      The dependency considered initialized when it is ready for use.

    3. Performs the module setup by invoking the setup method.

    Parameters

    • setup: Setup

      Context module setup.

    Returns Promise<void>

    A promise resolved when the module is set up asynchronously.

Generated using TypeDoc