import { createImpl } from './create-impl'; import type { SharedImpl } from './shared-impl'; export const STATE_KEY = Symbol.for('@servicetitan/datadog-rum'); export interface GlobalSlot { [STATE_KEY]?: SharedImpl; } function slot(): GlobalSlot { return globalThis as unknown as GlobalSlot; } /** Returns the shared impl, creating it if it doesn't exist yet. Only called by `init`. */ export function getOrCreateSharedImpl(): SharedImpl { const s = slot(); s[STATE_KEY] ??= createImpl(); return s[STATE_KEY]; } /** Returns the shared impl if it already exists, or `undefined`. */ export function getSharedImpl(): SharedImpl | undefined { return slot()[STATE_KEY]; }