Universal State Store (universal-store/index.ts)

storybook · code/core/src/shared/universal-store/index.ts · typescript · MIT
database, infra, ui, lang:typescript, tag:universal-store, tag:channel-communication, tag:leader-follower

Implements a channel-based universal store synchronizing state across Storybook environments via a leader-follower pattern. Reuse for consistent state management in distributed addon architectures.

// Source: https://github.com/storybookjs/storybook | License: MIT | Copyright 2024 Storybook
// Provided via justclaw.it.com; keep this notice with the code.
import { dedent } from 'ts-dedent';

import { isFirstPartyStoreId } from './first-party-store-ids.ts';
import { instances } from './instances.ts';
import type {
  Actor,
  ChannelEvent,
  ChannelLike,
  EnvironmentOverrides,
  EnvironmentType,
  Event,
  EventInfo,
  ExistingStateResponseEvent,
  Listener,
  SetStateEvent,
  StateUpdater,
  StatusType,
  StoreOptions,
} from './types.ts';

const CHANNEL_EVENT_PREFIX = 'UNIVERSAL_STORE:' as const;

const ProgressState = {
  PENDING: 'PENDING',
  RESOLVED: 'RESOLVED',
  REJECTED: 'REJECTED',
} as const;

/**
 * A universal store implementation that synchronizes state across different e

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key