import { RemoteData } from '@shared/application/remote-data'; /** The standard load-lifecycle tags an editor machine exposes. */ export type LoadLifecycle = { tag: 'loading' } | { tag: 'failed'; reason: string } | { tag: 'loaded' }; /** * Project an Elm-machine state onto `RemoteData` for the `` seam. The machine * keeps owning its own domain lifecycle (draft/submitted/…); this is purely the * loading/failed/loaded → async mapping, which was byte-identical across BriefStore, * OrgTemplateStore and StamdataStore (WP-31). Wrap the call in a `computed`. */ export function machineRemoteData( s: S, ): RemoteData> { switch (s.tag) { case 'loading': return { tag: 'Loading' }; case 'failed': return { tag: 'Failure', error: new Error(s.reason) }; default: // 'loaded' return { tag: 'Success', value: s as Extract }; } }