| 1 | import { useLayoutEffect, useMemo } from "react"; |
| 2 | import { useCommittedSlot, type CommittedSlot } from "./useCommittedSlot"; |
| 3 | import { createPendingRevisionOwner, type PendingRevisionInput } from "../app-runtime/pendingRevisionOwner"; |
| 4 | |
| 5 | function bindOwner(slot: CommittedSlot<PendingRevisionInput>) { |
| 6 | return createPendingRevisionOwner(() => slot.phase === "ready" && slot.value ? { epoch: slot.epoch, input: slot.value } : undefined); |
| 7 | } |
| 8 | export function reportPendingRevisionFailure(error: unknown) { |
| 9 | console.warn("Failed to submit pending plan revision", error); |
| 10 | } |
| 11 | |
| 12 | export function usePendingPlanRevisions(input: PendingRevisionInput) { |
| 13 | const slot = useCommittedSlot(input); |
| 14 | const owner = useMemo(() => bindOwner(slot), [slot]); |
| 15 | useLayoutEffect(() => { owner.pump(); }); |
| 16 | useLayoutEffect(() => () => owner.dispose(), [owner]); |
| 17 | return owner.remember; |
| 18 | } |
| 19 |