45 lines
2.0 KiB
TypeScript
45 lines
2.0 KiB
TypeScript
/* =============================================================================
|
|
* A00_Common/design/design_structure_status.ts
|
|
* 구조물 현황 한 벌(322-3) — 측점 계획 한 벌(`planStations`) → 종단 측점 목록(B05 종단 · 3D 막대 ·
|
|
* B06 종단 띠가 같은 꼴) · 관 · 구조물 · 추가 측점 초안 바뀜 신호.
|
|
*
|
|
* 구조물 id = 구조물은 structure_id · 관은 세션 id(`design_pipe_ids` · 323-5 · 파일 모양 그대로 · 저장 안 함).
|
|
* ========================================================================== */
|
|
|
|
// 측점 계획 → 종단 측점 = logic(511-B B-3) — 부르는 쪽은 그대로 여기서 받음
|
|
export { plannedIrregular } from "./logic/design_planted_base";
|
|
import { useDesignStore, type DesignStoreValues } from "./design_store";
|
|
|
|
/**
|
|
* 바뀜 신호 하나(323-6) — 관 · 구조물 · 추가 측점 초안을 구독(어느 길로 쓰든 설계 가게 한 곳). 구조물 = 늘 · 관 = 자리 · 종류 ·
|
|
* 구간 · 잇기가 바뀔 때만(옵션만 고친 것은 폼 길 `applyPipeOptions` 가 그 카드만 고침 — 카드 줌 · 팬 지킴).
|
|
* 돌려주는 함수로 끊음.
|
|
*/
|
|
export function watchDrafts(projectId: string | null, onChange: () => void): () => void {
|
|
const shop = useDesignStore(projectId, null);
|
|
type Pipe = NonNullable<DesignStoreValues["pipes"]>[number];
|
|
const layout = (pipes: ReadonlyArray<Pipe> | null): string =>
|
|
JSON.stringify(
|
|
(pipes ?? []).map((p) => [
|
|
p.chainage_m,
|
|
p.facility ?? "pipe",
|
|
p.start_m ?? null,
|
|
p.end_m ?? null,
|
|
p.summary_item ?? null,
|
|
p.group_items ?? null,
|
|
]),
|
|
);
|
|
let seen = layout(shop.get("pipes"));
|
|
const offs = [
|
|
shop.subscribe("structures", onChange),
|
|
shop.subscribe("plusStations", onChange), // 추가 측점(368-2)
|
|
shop.subscribe("pipes", (pipes) => {
|
|
const key = layout(pipes);
|
|
if (key === seen) return;
|
|
seen = key;
|
|
onChange();
|
|
}),
|
|
];
|
|
return () => offs.forEach((off) => off());
|
|
}
|