/** * V2 Core 초기화 * * 앱 시작 시 한 번 호출하여 V2 시스템을 초기화합니다. */ import { v2EventBus } from "./events"; import { legacyEventAdapter } from "./adapters"; let isInitialized = false; export interface V2CoreOptions { /** 디버그 모드 활성화 */ debug?: boolean; /** 레거시 이벤트 브릿지 설정 */ legacyBridge?: { /** 레거시 → V2 브릿지 활성화 (기본값: true) */ legacyToV2?: boolean; /** V2 → 레거시 브릿지 활성화 (기본값: true) */ v2ToLegacy?: boolean; }; } /** * V2 Core 초기화 * * @param options - 초기화 옵션 * * @example * ```typescript * // app/layout.tsx 또는 진입점에서 호출 * import { initV2Core } from "@/lib/v2-core"; * * // 기본 초기화 * initV2Core(); * * // 디버그 모드 및 커스텀 설정 * initV2Core({ * debug: process.env.NODE_ENV === "development", * legacyBridge: { * legacyToV2: true, * v2ToLegacy: true, * }, * }); * ``` */ export function initV2Core(options?: V2CoreOptions): void { if (isInitialized) { console.warn("[V2Core] 이미 초기화되어 있습니다."); return; } const { debug = process.env.NODE_ENV === "development", legacyBridge = { legacyToV2: true, v2ToLegacy: true }, } = options ?? {}; console.log("[V2Core] 초기화 시작..."); // 디버그 모드 설정 v2EventBus.debug = debug; // 레거시 이벤트 브릿지 초기화 legacyEventAdapter.init(legacyBridge); isInitialized = true; console.log("[V2Core] 초기화 완료", { debug, legacyBridge: legacyEventAdapter.active, }); } /** * V2 Core 정리 * * 테스트 또는 특수 상황에서 V2 시스템을 정리할 때 사용 */ export function cleanupV2Core(): void { if (!isInitialized) { return; } console.log("[V2Core] 정리 시작..."); // 레거시 어댑터 정리 legacyEventAdapter.destroy(); // 이벤트 버스 정리 v2EventBus.clear(); isInitialized = false; console.log("[V2Core] 정리 완료"); } /** * V2 Core 초기화 상태 확인 */ export function isV2CoreInitialized(): boolean { return isInitialized; }