Skip to content
docsv0.1.0

ComponentRendererInterface

Turns a mounted (or mountable) component into output for one {@see RenderTarget} — HTML, TUI, or ANSI. This is the render-target seam the whole package is built around: a component definition never renders itself, and a renderer never assumes which target it is asked for beyond what {@see supportsTarget()} declares. A single renderer MAY support only a subset of registered components (see each implementation's own allow-list) in addition to declaring which target(s) it supports.

ComponentRendererInterface::supportsTarget()

abstract public function supportsTarget(Milpa\Live\ValueObjects\RenderTarget $target): bool

Whether this renderer can produce output for the given target at all (independent of which specific component is being rendered). Used by {@see ComponentRendererRegistryInterface} to dispatch by target instead of renderers being hand-wired per call site.

Parameters

Parameters of supportsTarget()
NameTypeDescription
$targetMilpa\Live\ValueObjects\RenderTarget

ComponentRendererInterface::render()

abstract public function render(Milpa\Live\Contracts\Component\ComponentDefinitionInterface $component, Milpa\Live\ValueObjects\RenderRequest $request): Milpa\Live\ValueObjects\RenderResult

Renders the component for this renderer's target. If {@see RenderRequest::$state} is `null`, implementations MUST mount the component first (via {@see ComponentDefinitionInterface::mount()}) using {@see RenderRequest::$props} and {@see RenderRequest::$context} before rendering it, and MUST return that freshly-mounted snapshot as {@see RenderResult::$state}. If `$state` is already provided (e.g. re-rendering after {@see ComponentDefinitionInterface::handle()}), implementations render that snapshot as-is instead of remounting.

Parameters

Parameters of render()
NameTypeDescription
$componentMilpa\Live\Contracts\Component\ComponentDefinitionInterface
$requestMilpa\Live\ValueObjects\RenderRequest

Throws

\InvalidArgumentException If the component's {@see \Milpa\Live\ValueObjects\ComponentContract::$name} is not one this renderer supports.