Files
likang 1fde96c05e
CI / typecheck + test + build (push) Has been cancelled
打通vibemake
2026-11-05 16:21:37 +08:00

26 lines
877 B
TypeScript

// SPDX-License-Identifier: GPL-3.0-or-later
import { useEffect, useRef } from 'react';
import { projectSnapshotHost, type ProjectSnapshotParticipant } from './project_snapshot.js';
/** Callbacks follow the live frame; identity is captured only at mount. */
export function useProjectSnapshot(
key: string,
participant: ProjectSnapshotParticipant,
revision: unknown,
): void {
const host = useRef(projectSnapshotHost()).current;
const live = useRef(participant);
live.current = participant;
useEffect(
() =>
host?.register(key, {
flush: () => live.current.flush(),
isDirty: () => live.current.isDirty?.() ?? false,
isBusy: () => live.current.isBusy?.() ?? false,
}),
[host, key],
);
useEffect(() => {
if (revision !== undefined && (live.current.isDirty?.() ?? true)) host?.modified();
}, [host, revision]);
}