You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Based on #35 we can use the integration API via ::create to handle component proxies (or builders actually?), that gather additional information before calling expensive methods like image URI rendering.
Given Kaleidoscope defines the ImageTag component from before, it can now create a component proxy as follows:
Note that it does not implement the component interface, it must not be rendered directly! We could implement a render() method though that throws a meaningful exception that the proxy must be resolved before rendering.
Additionally, to make things less easy, we add an intermediary Figure component as follows:
export component Figure {
image: ImageTag with proxy ImageTagProxy // or similar
caption: string
return <figure class="figure">
{image}
<figcaption>{caption}</figcaption>
</figure>
}
which transpiles to
finalreadonlyclass Figure extends AbstractComponent
{
/** * @internal only for deserialization */publicfunction__construct(
publicImageTag|ImageTagProxy$image,
publicstring$caption,
) {
}
/** * @api to be used in integration */publicstaticfunctioncreate(
ImageTagProxy$image,
string$caption
): self {
returnnewself(
$image,
$caption,
);
}
/** * @internal for prop merge only */publicfunctionwith(
?ImageTag$image = null,
?string$caption = null,
): self {
returnnewself(
$image,
$caption,
);
}
publicfunctionrender(): string
{
return'<figure class="figure">' . $this->image . ' <figcaption>' . $this->caption . '</figcaption> </figure>';
}
}
We now adjust our card component as follows:
export component Card {
media: Figure {
image {
// here we enforce the responsive image sizes etc. for the image in the figure in this component
mediaDescriptors: "whatever"
...
}
}
headline: Headline {
size: 'large' // here we enforce headline size for this component
}
return <div class="card">
{media} // here we just render the figure without calling its constructor
{headline} // same for the headline
</div>
}
which now transpiles to
finalreadonlyclass Card extends AbstractComponent
{
/** * @internal only for deserialization */publicfunction__construct(
privateFigure$media,
privateHeadline$headline,
) {
}
publicstaticfunctioncreate(
Figure$media,
Headline$headline,
): self {
returnnewself(
media: $media->imageinstanceof ImageTagProxy
? newFigure(
// here we have all necessary parameters and can resolve before rendering!
image: $media->image->with(mediaDescriptors: 'whatever')->resolve(),
caption: $media->caption
)
: $picture,
headline: $headline->with(variant: HeadlineVariant::VARIANT_LARGE),
);
}
publicfunctionrender(): string
{
return'<div class="card">' . $this->media . '' . $this->header . ' </div>';
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Based on #35 we can use the integration API via ::create to handle component proxies (or builders actually?), that gather additional information before calling expensive methods like image URI rendering.
Given Kaleidoscope defines the
ImageTag
component from before, it can now create a component proxy as follows:Note that it does not implement the component interface, it must not be rendered directly! We could implement a render() method though that throws a meaningful exception that the proxy must be resolved before rendering.
Additionally, to make things less easy, we add an intermediary Figure component as follows:
which transpiles to
We now adjust our card component as follows:
which now transpiles to
In the PHP integration we can now call
This way we can instantiate a component
WDYT?
Beta Was this translation helpful? Give feedback.
All reactions