feat: ComponentScript spread attribute support #595
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
For context, there were a couple threads (1, 2) in the templ slack channel asking about support for
ComponentScript
attributes in the spread attribute functionality. This was just a quick exploratory attempt at this feature so I'm open to suggestions on the resulting generated code. The resulting HTML after rendering is effectively the same as if the script function were passed in directly instead of through a spread attribute.The existing implementation only renders
<script>
elements from script components when directly provided in anExpressionAttribute
with the generated code as follows.This proposed change will provide all spread attributes used within the element to a new
RenderScriptItemsWithSpread
that takes in a slice ofAttributes
and on runtime will loop over all attributes to discover any script components to render.Upon opening this PR, the implementation is set up so that providing spread attributes at all to an element will cause it to generate code with the new
RenderScriptItemsWithSpread
due to the unknown of what parameters might be passed in through the spread.