ManagedComponent

interface ManagedComponent<T>

This interface should be implemented by all components, that should appear at a specific, centralized node within the DOM tree. Think of modals or toasts for example: They appear as overlays above all other screen elements, which is realized by a central parent node in the DOM.

The render method has to be implemented in order to do the actual rendering of one component. This reduces the boilerplate code within the corresponding factory function(s):

open class MyManagedComponent: ManagedComponent {
override fun render(...) {
// some content rendering
}
}

// factory don't need to be an extension of `RenderContext`!
myComponent(
// most params omitted
build: MyManagedComponent.() -> Unit = {}
) {
MyComponent().apply(build).render(/* params */)
// ^^^^^^ ^^^^^^^^^^^^
// | no reference to parent's `RenderContext` is needed!
// | (in contrast to `Component<T>` interface!)
// |
// just start the rendering by one additional call!
}

To start the centralized rendering process, consider using the init block of a companion object:

open class MyManagedComponent: ManagedComponent {
companion object {
init {
ManagedComponent.managedRenderContext("someId", Job()).apply {
// do the central rendering (often surrounded by some central store, that manages the child
// components added by the factory functions)
}
}
}

override fun render(...) {
// some content rendering
}
}

See also

Types

Companion
Link copied to clipboard
js
object Companion

Functions

render
Link copied to clipboard
js
abstract fun render(styling: BoxParams.() -> Unit, baseClass: StyleClass, id: String?, prefix: String): T
Central method that should do the actual rendering of a managed component.

Inheritors

ModalComponent
Link copied to clipboard
ToastComponentBase
Link copied to clipboard