BaseRenderContext

Facilities for a Workflow to interact with other Workflows and the outside world from inside a render function.

Handling events from the UI

While a workflow's rendering can represent whatever you need it to, it is common for the rendering to contain the data for some part of your UI. In addition to shuttling data to the UI, the rendering can also contain functions that the UI can call to send events to the workflow.

E.g.

data class Rendering(
val radioButtonTexts: List<String>,
val onSelected: (index: Int) -> Unit
)

To create populate such functions from your render method, you first need to define a WorkflowAction to handle the event by changing state, emitting an output, or both. Then, just pass a lambda to your rendering that instantiates the action and passes it to actionSink.send.

Performing asynchronous work

See runningWorker.

Composing children

See renderChild.

Inheritors

Properties

Link copied to clipboard

Accepts a single WorkflowAction, invokes that action by calling WorkflowAction.apply to update the current state, and optionally emits the returned output value if it is non-null.

Functions

Link copied to clipboard
open fun <E1, E2, E3, E4, E5, E6, E7, E8, E9> eventHandler(name: () -> String = { "eventHandler" }, update: WorkflowAction.Updater<@UnsafeVariance PropsT, StateT, @UnsafeVariance OutputT>.(E1, E2, E3, E4, E5, E6, E7, E8, E9) -> Unit): (E1, E2, E3, E4, E5, E6, E7, E8, E9) -> Unit
open fun <E1, E2, E3, E4, E5, E6, E7, E8, E9, E10> eventHandler(name: () -> String = { "eventHandler" }, update: WorkflowAction.Updater<@UnsafeVariance PropsT, StateT, @UnsafeVariance OutputT>.(E1, E2, E3, E4, E5, E6, E7, E8, E9, E10) -> Unit): (E1, E2, E3, E4, E5, E6, E7, E8, E9, E10) -> Unit
open fun <EventT> eventHandler(name: () -> String = { "eventHandler" }, update: WorkflowAction.Updater<@UnsafeVariance PropsT, StateT, @UnsafeVariance OutputT>.(EventT) -> Unit): (EventT) -> Unit
open fun <E1, E2> eventHandler(name: () -> String = { "eventHandler" }, update: WorkflowAction.Updater<@UnsafeVariance PropsT, StateT, @UnsafeVariance OutputT>.(E1, E2) -> Unit): (E1, E2) -> Unit
open fun <E1, E2, E3> eventHandler(name: () -> String = { "eventHandler" }, update: WorkflowAction.Updater<@UnsafeVariance PropsT, StateT, @UnsafeVariance OutputT>.(E1, E2, E3) -> Unit): (E1, E2, E3) -> Unit
open fun <E1, E2, E3, E4> eventHandler(name: () -> String = { "eventHandler" }, update: WorkflowAction.Updater<@UnsafeVariance PropsT, StateT, @UnsafeVariance OutputT>.(E1, E2, E3, E4) -> Unit): (E1, E2, E3, E4) -> Unit
open fun <E1, E2, E3, E4, E5> eventHandler(name: () -> String = { "eventHandler" }, update: WorkflowAction.Updater<@UnsafeVariance PropsT, StateT, @UnsafeVariance OutputT>.(E1, E2, E3, E4, E5) -> Unit): (E1, E2, E3, E4, E5) -> Unit
open fun <E1, E2, E3, E4, E5, E6> eventHandler(name: () -> String = { "eventHandler" }, update: WorkflowAction.Updater<@UnsafeVariance PropsT, StateT, @UnsafeVariance OutputT>.(E1, E2, E3, E4, E5, E6) -> Unit): (E1, E2, E3, E4, E5, E6) -> Unit
open fun <E1, E2, E3, E4, E5, E6, E7> eventHandler(name: () -> String = { "eventHandler" }, update: WorkflowAction.Updater<@UnsafeVariance PropsT, StateT, @UnsafeVariance OutputT>.(E1, E2, E3, E4, E5, E6, E7) -> Unit): (E1, E2, E3, E4, E5, E6, E7) -> Unit
open fun <E1, E2, E3, E4, E5, E6, E7, E8> eventHandler(name: () -> String = { "eventHandler" }, update: WorkflowAction.Updater<@UnsafeVariance PropsT, StateT, @UnsafeVariance OutputT>.(E1, E2, E3, E4, E5, E6, E7, E8) -> Unit): (E1, E2, E3, E4, E5, E6, E7, E8) -> Unit

open fun eventHandler(name: () -> String = { "eventHandler" }, update: WorkflowAction.Updater<@UnsafeVariance PropsT, StateT, @UnsafeVariance OutputT>.() -> Unit): () -> Unit

Creates a function which builds a WorkflowAction from the given update function, and immediately passes it to actionSink. Handy for attaching event handlers to renderings.

Link copied to clipboard

Ensures child is running as a child of this workflow, and returns the result of its render method.

Link copied to clipboard
Link copied to clipboard
abstract fun runningSideEffect(key: String, sideEffect: suspend CoroutineScope.() -> Unit)

Ensures sideEffect is running with the given key.

Link copied to clipboard

Ensures a LifecycleWorker is running. Since worker can't emit anything, it can't trigger any WorkflowActions.

inline fun <T, W : Worker<T>, PropsT, StateT, OutputT> BaseRenderContext<PropsT, StateT, OutputT>.runningWorker(worker: W, key: String = "", noinline handler: (T) -> WorkflowAction<PropsT, StateT, OutputT>)

Ensures worker is running. When the Worker emits an output, handler is called to determine the WorkflowAction to take. When the worker finishes, nothing happens (although another render pass may be triggered).