# InMemoryLaunchDarklyClient

An in-memory implementation of the LaunchDarkly SDK client for use in Storybook and test environments.

# Reference

const client = new InMemoryLaunchDarklyClient(featureFlags, options?: { context?, notifier? })

# Parameters

  • featureFlags: A map instance of feature flags.
  • options: An optional object literal of options:
    • context: A LaunchDarkly SDK context.
    • notifier: A LaunchDarklyClientNotifier instance.

# Usage

# Create an instance

import { InMemoryLaunchDarklyClient } from "@squide/firefly";

const featureFlags = new Map([
    ["show-characters", true]
] as const);

const client = new InMemoryLaunchDarklyClient(featureFlags);

# Update the in-memory flags

import { InMemoryLaunchDarklyClient } from "@squide/firefly";

const featureFlags = new Map([
    ["show-characters", true]
] as const);

const client = new InMemoryLaunchDarklyClient(featureFlags);

featureFlags.set("show-characters", true);

# Fake a notification

import { InMemoryLaunchDarklyClient, LaunchDarklyClientNotifier } from "@squide/firefly";

const featureFlags = new Map([
    ["show-characters", true]
] as const);

const notifier = new LaunchDarklyClientNotifier();

const client = new InMemoryLaunchDarklyClient(featureFlags, {
    notifier
});

notifier.notify("change", {
    "show-characters": false
});

# Customize the context

By default client context is { kind: "user", anonymous: true }. To customize the context, provide a context option.

import { InMemoryLaunchDarklyClient } from "@squide/firefly";

const featureFlags = new Map([
    ["show-characters", true]
] as const);

const client = new InMemoryLaunchDarklyClient(featureFlags, {
    context: {
        kind: "multi",
        user: {
            key: "user-123",
            name: "Sandy",
            email: "sandy@example.com"
        },
        org: {
            key: "org-456",
            name: "Acme Inc",
            plan: "enterprise"
        }
    }
});