Core 1.0.0-rc.1
createJourneyMachine Assembly
Source file: packages/core/src/journey-machine/index.ts
This file is the composition root for the core runtime.
It does not implement guard evaluation, navigation commits, or plugin behavior itself. Its job is to validate the definition, construct the controllers in the right order, and expose one public machine object.
How It Works
- It validates the raw journey shape before any controller exists:
stepsmust be a recordtransitionsmust be an array or object map when provided- reserved step ids such as
COMPLETEandTERMINATEDare rejected - the initial step must exist
- It resolves the authored definition with
resolveJourneyDefinition(...)and then validates the resulting transition list withvalidateJourneyTransitions(...). - It prepares two pieces of initial runtime state:
- a private step-metadata record cloned from each step's static
meta buildInitialSnapshot()to create the initial snapshot with history, visited flags, status, and async state
- a private step-metadata record cloned from each step's static
- It creates the plugin controller first so plugins can hydrate the initial snapshot before the runtime starts.
- It creates the runtime, then the async-state, navigation, send, and controls controllers, passing each one only the dependencies it needs.
- It assembles the public machine API:
- snapshot reads and subscriptions come from the runtime
- transition-driven helpers queue through the runtime
- non-transition mutations come from controls
- convenience event subscriptions filter the lifecycle stream
- It finally lets plugins augment the machine surface with
pluginController.extendMachine(...).
Why The Order Matters
The order is deliberate:
- the resolver must run before anything can evaluate transitions
- plugin hydration must happen before the runtime owns the first snapshot
- the runtime must exist before async, navigation, send, or controls can commit state
- plugin augmentation must happen last so the returned machine is complete
That keeps every controller small and prevents hidden initialization dependencies.
Recommended Reading
- Read Journey Definition Resolver for the normalization step this file depends on.
- Read Runtime Queue for the state container this file creates.
- Read Plugin Lifecycle for hydration and machine augmentation.
- Read Core API Overview or Quickstart if you want to switch back from internals to public usage.