/** * 워크스페이스 slot0 보조지표 — 알림 미니 차트가 메인 차트 인스턴스 스타일과 맞추도록 */ import type { IndicatorConfig } from '../types'; import { loadWorkspace } from './backendApi'; let cached: IndicatorConfig[] | null = null; let loadPromise: Promise | null = null; let loadedSessionKey: number | null = null; export function invalidateWorkspaceChartIndicatorsCache(): void { cached = null; loadPromise = null; loadedSessionKey = null; } export function ensureWorkspaceChartIndicators(sessionKey = 0): Promise { if (cached !== null && loadedSessionKey === sessionKey) { return Promise.resolve(cached); } if (loadedSessionKey !== sessionKey) { cached = null; loadPromise = null; } if (!loadPromise) { loadPromise = loadWorkspace() .then(ws => { const slot0 = (Array.isArray(ws?.slots) ? ws.slots[0] : null) as | { indicators?: IndicatorConfig[] } | null; cached = Array.isArray(slot0?.indicators) ? slot0!.indicators! : []; loadedSessionKey = sessionKey; loadPromise = null; return cached; }) .catch(() => { cached = []; loadedSessionKey = sessionKey; loadPromise = null; return []; }); } return loadPromise; } export function getWorkspaceChartIndicatorsCache(): IndicatorConfig[] | null { return cached; }