Sync / foldkit-sync/metakit
fromMachine
function · packages/sync/src/machine.ts:47
function fromMachine<
Root,
Shared,
Transitions extends Readonly<Record<string, unknown>>,
const Tags extends ReadonlyArray<keyof Transitions & string>,
>(
machine: Machine<Root, Transitions>,
tags: Tags,
shared: {
readonly dependencies: ReadonlyArray<ReadonlyArray<string>>
readonly get: (root: Root) => Shared
readonly set: (root: Root, shared: Shared) => Root
},
initial: Root,
): {
readonly [K in Tags[number]]: DeclaredTransition<
Shared,
InputOf<Transitions[K]>
>
}Extracts the durable subset of an application's metakit Machine for
Sync.forApplication(App).make({ transitions }), throwing at definition for
a tag whose transition:
- is not a transition of the Machine;
- emits a Command (durable transitions are state-only);
- declares supplied values (a replay passes none, so every replay would be refused);
- has a read it does not bound (an opaque term may read outside the shared slice);
- reads or writes a path that is not inside the shared slice (the shared slice's path must be a prefix of it, so a write to a parent of the slice is refused).
It does not check the document's laws, or for an unreachable guard: a replay
runs on the shared slice over initial, as forApplication does. Use
SyncDeclared.transition for those checks.