initializeFireflyForStorybook

Create a runtime instance tailored for Storybook and optionally register local modules.

Reference

const runtime = initializeFireflyForStorybook<TData = unknown>(options?: { localModules?, environmentVariables?, featureFlags?, launchDarklyClient?, loggers?, useMsw? })

Type parameters

  • TData: An optional type describing the data passed to deferred registration functions returned by localModules. Defaults to unknown.

Parameters

  • options: An optional object literal of options:
    • localModules: An optional array of ModuleRegisterFunction<FireflyRuntime, unknown, TData>.
    • environmentVariables: An optional object of environment variables.
    • featureFlags: An optional Map instance of feature flags.
    • launchDarklyClient: An optional LaunchDarkly client to override the default client.
    • loggers: An optional array of logger instances.
    • useMsw: An optional boolean value indicating whether or not to create the runtime with Mock Service Work (MSW) support. Default is true.
    • additionalPlugins: An optional array with additional plugins to be registered with the runtime.

Returns

A Promise resolving to a StorybookRuntime instance.

Usage

Initialize with local modules

import { initializeFireflyForStorybook } from "@squide/firefly-storybook";

const runtime = initializeFireflyForStorybook({
    localModules: [...]
});

Initialize with environment variables

import { initializeFireflyForStorybook } from "@squide/firefly-storybook";

const runtime = initializeFireflyForStorybook({
    environmentVariables: {
        "foo": "bar"
    }
});

Initialize with feature flags

import { initializeFireflyForStorybook } from "@squide/firefly-storybook";

const runtime = initializeFireflyForStorybook({
    featureFlags: {
        "show-characters": true
    }
});

Initialize with a LaunchDarkly client

import { initializeFireflyForStorybook } from "@squide/firefly-storybook";
import { InMemoryLaunchDarklyClient } from "@squide/firefly";

const launchDarklyClient = new InMemoryLaunchDarklyClient(featureFlags);

const runtime = initializeFireflyForStorybook({
    featureFlags: {
        "show-characters": true
    },
    launchDarklyClient
});

Initialize without MSW support

import { initializeFireflyForStorybook } from "@squide/firefly-storybook";

const runtime = initializeFireflyForStorybook({
    useMsw: false
});

Initialize with i18next

import { initializeFireflyForStorybook } from "@squide/firefly-storybook";
import { i18nextPlugin } from "@squide/i18next";

const runtime = initializeFireflyForStorybook({
    additionalPlugins: [x => new i18nextPlugin(x, ["en-US", "fr-CA"], "en-US", "language")]
});

Initialize with typed deferred registration data

Pass a TData type argument so that the data forwarded to deferred registration functions is strongly typed.

import { initializeFireflyForStorybook } from "@squide/firefly-storybook";
import type { ModuleRegisterFunction, FireflyRuntime } from "@squide/firefly";

interface DeferredData {
    subscription: { tier: "free" | "pro" | "enterprise" };
}

const registerModule: ModuleRegisterFunction<FireflyRuntime, unknown, DeferredData> = runtime => {
    return (runtime, data, operation) => {
        if (data.subscription.tier === "enterprise") {
            // Register routes/navigation only available to enterprise tenants.
        }
    };
};

const runtime = initializeFireflyForStorybook<DeferredData>({
    localModules: [registerModule]
});