Function createModule

  • Parameters

    • init: any

    Returns {
        create_map_factory: (() => ((env) => any));
        impl: ((callback) => void);
    }

    • create_map_factory: (() => ((env) => any))
        • (): ((env) => any)
        • Returns ((env) => any)

            • (env): any
            • Parameters

              • env: any

              Returns any

    • impl: ((callback) => void)
        • (callback): void
        • Parameters

          • callback: any

          Returns void

    Stability

    1 - experimental

    Creates a module which is an intermediate organizational tool for building a map.

    It handles:

    1. Initialization
    2. Environment (dependency) capturing
    3. Self-referencing
    4. Segregating implementation into chunks, for the purpose of allowing the developer to split the implementation across files.
    5. Obtaining a final map factory for export.

    Takes in an optional async initialization function, which takes in the environment (a map) provided by the developer when they invoke the map factory, and returns an updated environment which is passed to your implementation, allowing for any needed initialization logic.

    Example

    // mod.ts

    import function_a from "./function_a.js";
    import function_b from "./function_b.js";

    const module = create_module(async (env) => {
    // initialization logic here
    });

    module.impl(function_a);
    module.impl(function_b);

    export default module.create_map_factory();

    // function_a.js

    export default (env) => [
    ["function_a", "banana"],
    ];

    // function_b.js

    export default (env) => [
    ["function_b", "octopus"],
    ];

    // main.ts

    import create_map from "./mod.js";

    const map = create_map();

    await map.function_a(); // "banana"
    await map.function_b(); // "octopus"

Generated using TypeDoc