# completeModuleRegistrations

Completes the registration process for modules that have been registred using registerLocalModules and registerRemoteModules by executing the registered deferred registration functions.

# Reference

completeModuleRegistrations(runtime, data?)

# Parameters

  • runtime: A FireflyRuntime instance.
  • data: An optional object with data to forward to the deferred registration functions.

# Returns

  • A Promise object with the following properties:
    • localModuleErrors: An array of LocalModuleRegistrationError if any error happens during the completion of the local modules registration process.
    • remoteModuleErrors: An array of RemoteModuleRegistrationError if any error happens during the completion of the remote modules registration process.

# Usage

# Complete module registrations

host/src/bootstrap.tsx
import { registerLocalModules, FireflyRuntime, completeModuleRegistrations, registerRemoteModules, type RemoteDefinition } from "@squide/firefly";
import { register } from "@sample/local-module";
import { fetchFeatureFlags } from "@sample/shared";

const runtime = new FireflyRuntime();

const Remotes: RemoteDefinition = [
    { name: "remote1" }
];

await registerLocalModules([register], runtime);
await registerRemoteModules(Remotes, runtime);

// Don't fetch data in the bootstrapping code for a real application. This is done here
// strictly for demonstration purpose.
const featureFlags = await fetchFeatureFlags();

// Complete the local module and remote module registrations with the feature flags data.
await completeModuleRegistrations(runtime, { featureFlags });
remote-module/src/register.tsx
import type { ModuleRegisterFunction, FireflyRuntime } from "@squide/firefly";
import type { DeferredRegistrationData } from "@sample/shared";
import { AboutPage } from "./AboutPage.tsx";
import { FeatureAPage } from "./FeatureAPage.tsx";

export const register: ModuleRegisterFunction<FireflyRuntime, unknown, DeferredRegistrationData> = async runtime => {
    runtime.registerRoute({
        path: "/about",
        element: <AboutPage />
    });

    runtime.registerNavigationItem({
        $label: "About",
        to: "/about"
    });

    // Once the feature flags has been loaded by the host application, by completing the module registrations process,
    // the deferred registration function will be called with the feature flags data.
    return ({ featureFlags } = {}) => {
        // Only register the "feature-a" route and navigation item if the feature is active.
        if (featureFlags.featureA) {
            runtime.registerRoute({
                path: "/feature-a",
                element: <FeatureAPage />
            });

            runtime.registerNavigationItem({
                $label: "Feature A",
                to: "/feature-a"
            });
        }
    };
}

# Handle the completion errors

host/src/bootstrap.tsx
import { registerLocalModules, FireflyRuntime, completeModuleRegistrations, registerRemoteModules, type RemoteDefinition } from "@squide/firefly";
import { register } from "@sample/local-module";
import { fetchFeatureFlags } from "@sample/shared";

const runtime = new FireflyRuntime();

const Remotes: RemoteDefinition = [
    { name: "remote1" }
];

await registerLocalModules([register], runtime);
await registerRemoteModules(Remotes, runtime);

// Don't fetch data in the bootstrapping code for a real application. This is done here
// strictly for demonstration purpose.
const featureFlags = await fetchFeatureFlags();

const errors = await completeModuleRegistrations(runtime, { featureFlags });

errors.localModuleErrors.forEach(x => {
    console.log(x);
});

errors.remoteModuleErrors.forEach(x => {
    console.log(x);
});