Skip to content
docsv0.1.0

ClientRuntimeAdapterInterface

The client-side JS runtime a rendered component boots into (e.g. Alpine). A renderer that produces markup for a live client MUST consult this contract instead of hardcoding runtime-specific attributes or bootstrap data, so swapping the client runtime does not require touching the renderer. Implementations are stateless: every method is a pure projection of its arguments.

ClientRuntimeAdapterInterface::name()

abstract public function name(): string

The runtime's identifier (e.g. `'alpine'`), also embedded verbatim into {@see rootAttributes()} and {@see bootPayload()} so the client can self-identify which runtime rendered a given root.

ClientRuntimeAdapterInterface::rootAttributes()

abstract public function rootAttributes(Milpa\Live\ValueObjects\ComponentContract $contract, Milpa\Live\ValueObjects\StateSnapshot $state): array

Attributes that the renderer should add to the component root.

Parameters

Parameters of rootAttributes()
NameTypeDescription
$contractMilpa\Live\ValueObjects\ComponentContract
$stateMilpa\Live\ValueObjects\StateSnapshot

ClientRuntimeAdapterInterface::bootPayload()

abstract public function bootPayload(array $contracts): array

The payload embedded on the page so the client runtime knows which component contracts it must be ready to boot.

Parameters

Parameters of bootPayload()
NameTypeDescription
$contractsarray<int, ComponentContract>All contracts the current page/response may render.

Returns

Runtime-specific, JSON-serializable boot payload.

ClientRuntimeAdapterInterface::assets()

abstract public function assets(): array

The static client-runtime assets (e.g. `<script>` src) the page MUST include for the runtime to function.

Returns

Asset kind (e.g. `'script'`) => URL.