ComponentDefinitionInterface
A live component: the render-target-agnostic unit this package orchestrates. A definition owns no rendering itself — turning its state into markup/TUI frames is the job of a {@see \Milpa\Live\Contracts\Rendering\ComponentRendererInterface} the caller pairs it with — but it DOES own the component's shape ({@see contract()}), its initial state ({@see mount()}), and how it reacts to client-originated actions ({@see handle()}).
ComponentDefinitionInterface::contract()
abstract public static function contract(): Milpa\Live\ValueObjects\ComponentContractThe component's machine-readable, render-target-agnostic contract (name, schema, declared actions/data sources). MUST be a pure function of the class — no instance state — since callers use it as a static registry key (see {@see \Milpa\Live\Contracts\Component\ComponentRegistryInterface}).
ComponentDefinitionInterface::mount()
abstract public function mount(array $props, Milpa\Live\ValueObjects\ComponentContext $context): Milpa\Live\ValueObjects\StateSnapshotBuilds the component's initial {@see StateSnapshot} from mount-time props. Called once per component lifecycle, before any {@see handle()} call. A caller that already holds a valid snapshot (e.g. one round-tripped from the client) MAY skip mount() and render that snapshot directly instead of remounting.
Parameters
| Name | Type | Description |
|---|---|---|
| $props | array<string, mixed> | Mount-time props, as passed by the caller (e.g. template attributes). |
| $context | Milpa\Live\ValueObjects\ComponentContext |
ComponentDefinitionInterface::handle()
abstract public function handle(Milpa\Live\ValueObjects\InteractionRequest $request): Milpa\Live\ValueObjects\InteractionResultApplies a client-originated action to the component's current state and returns the resulting state plus any side effects. {@see StateSnapshot} is immutable, so implementations MUST return a new snapshot via {@see InteractionResult::$state} rather than mutating {@see InteractionRequest::$state} in place. An unrecognized {@see InteractionRequest::$action} SHOULD be reported via {@see InteractionResult::$errors} rather than thrown, so the caller can surface it to the client instead of failing the request outright.
Parameters
| Name | Type | Description |
|---|---|---|
| $request | Milpa\Live\ValueObjects\InteractionRequest |