TagHook

abstract class TagHook<R : Tag<*>, P, I> : Hook<RenderContext, R, TagPayload<P>>

This hook abstraction simplifies a Tag creating Hook by offering static invoke methods, which already deal with constructing the value field, so that an abstract renderTag method is called. This covers the typical use case where a client only wants to configure exactly one value (flow or static) and the hook should use this to render some artifact.

A good example would be a hook for rendering some icon; it would accept a special `IconDefinition` and render some `<svg>`-tag including sub-tags:

class IconHook : TagHook<Svg, Null, IconDefinition>() {
override fun RenderContext.renderTag(classes: String?, id: String?, data: IconDefinition, payload: Unit): Svg {
svg(classes, id) {
// set some attributes based upon the fields of imaginary ``IconDefinition``
}
}
}

So the client can easily call this:

// a component exposes this hook:
class SomeComponent {
val closeIcon = IconHook()
}

// Client configures this easily:
closeIcon(Icons.close)

Its main motivation is to reduce the repeating boilerplate code of exactly the same invoke method implementations.

See also

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
var alsoExpr: R.() -> Unit?

This field encapsulates some behaviour, which should be applied to the result R of the Hook's Effect.

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun also(expr: R.() -> Unit)

This method offers the created result as receiver within a context expression in order to expose some additional configuration entry point for a client.

Link copied to clipboard
operator fun invoke(value: I): TagHook<R, P, I>
operator fun invoke(value: Flow<I>): TagHook<R, P, I>
Link copied to clipboard