Skip to content

Add value slots to the generated element API - #2

Merged
fmcarvalho merged 2 commits into
devfrom
feat/value-slots
Oct 22, 2026
Merged

fmcarvalho merged 2 commits into
devfrom
feat/value-slots

Conversation

@BernardoPe

@BernardoPe BernardoPe commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

This adds value slots to the generated element API.

The new textOf, rawOf, intOf, longOf, doubleOf, boolOf, attrOf and attrOfNullable methods allow a single value to be read from the model without using a dynamic() block.

forEachOf and whenOf use the same approach for loops and conditionals. Their bodies receive a Slot<M> so the model type can be inferred correctly inside the lambda. Slot provides read, readInt, readLong, readDouble and readBool, which return the accessor unchanged and only exist to provide the type information needed by the lambda.

The changes are additive, so existing implementations of ElementVisitorBase do not need to implement any new methods.

Numeric attribute setters also get primitive overloads, for example attrColspan(int), so callers do not need to box a value before converting it to a string.

This is used by HtmlFlow#149.

textOf/rawOf/intOf/longOf/doubleOf/boolOf/attrOf/attrOfNullable bind
a single value from the model without a dynamic() block. forEachOf
and whenOf preencode loops and conditionals the same way. A Slot<M>
scope object fixes the model type for a block's lambdas, since the
slot methods otherwise take an unbounded type parameter.

Also generates a primitive overload for numeric attribute setters,
avoiding a box before String.valueOf.
Like forEachOf, but each item comes with its position, starting at 0,
as an Indexed<E> with item() and index(). Templates that number rows or
alternate row classes no longer need to build a wrapper list per render.
The items are paired lazily as the loop reaches them.
@fmcarvalho
fmcarvalho merged commit e39a0ed into dev Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants