Files
Aislo/B06_Section/B06_Section_Swap_Bus.ts
T

37 lines
1.7 KiB
TypeScript

/* =============================================================================
* B06_Section_Swap_Bus.ts
* 상세 갈아끼움 알림판(PLAN 346-2) — 측점 수가 바뀌어 `Section_Store` 가 상세 객체를 갈아끼우면 여기로 알림.
* 가져오는 것 없음 — 측점 열쇠(`Station_Keys`) · 암 경계 저장소(`_UI_Page_Persist`)가 모듈을 읽을 때
* 붙어도 `Section_Store` 와 돌고 도는 가져오기가 안 생김.
* ========================================================================== */
import type { SectionDetailResponse } from "./B06_Section_Api_Types";
/** 새 상세 · 이어 받은 측점의 누가거리 옮김(옛 0.01 m 글 → 새 글 · 조작값 맵을 옮길 때). */
export type DetailListener = (
detail: SectionDetailResponse,
moves: ReadonlyMap<string, string>,
) => void;
const anyListeners = new Set<DetailListener>();
/** 어느 노선이든 상세가 갈아끼워지면 부름(조정창 값 · 암 경계 옮김 · 다시 그림) — 돌려준 함수로 끊음. */
export function onAnySwap(fn: DetailListener): () => void {
anyListeners.add(fn);
return () => anyListeners.delete(fn);
}
const afterListeners = new Set<DetailListener>();
/** 갈아끼움 알림이 다 돈 뒤 부름(세션 누가거리 칸 옮김 · `Station_Keys`). */
export function afterAnySwap(fn: DetailListener): () => void {
afterListeners.add(fn);
return () => afterListeners.delete(fn);
}
/** 갈아끼운 쪽(`Section_Store`)이 부름. */
export function emitSwap(detail: SectionDetailResponse, moves: ReadonlyMap<string, string>): void {
anyListeners.forEach((fn) => fn(detail, moves));
afterListeners.forEach((fn) => fn(detail, moves));
}