Skip to content

//workflow/com.squareup.workflow1/BaseRenderContext

BaseRenderContext

[jvm] interface BaseRenderContextPropsT, StateT, in OutputT>

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,
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.

Functions

Name Summary
eventHandler [jvm]
Content
open fun <E1, E2, E3, E4, E5, E6, E7, E8, E9> eventHandler(name: () -> String = { “eventHandler” }, update: WorkflowAction.Updater<PropsT, StateT, 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<PropsT, StateT, 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<PropsT, StateT, OutputT>.(EventT) -> Unit): (EventT) -> Unit
open fun <E1, E2> eventHandler(name: () -> String = { “eventHandler” }, update: WorkflowAction.Updater<PropsT, StateT, OutputT>.(E1, E2) -> Unit): (E1, E2) -> Unit
open fun <E1, E2, E3> eventHandler(name: () -> String = { “eventHandler” }, update: WorkflowAction.Updater<PropsT, StateT, OutputT>.(E1, E2, E3) -> Unit): (E1, E2, E3) -> Unit
open fun <E1, E2, E3, E4> eventHandler(name: () -> String = { “eventHandler” }, update: WorkflowAction.Updater<PropsT, StateT, 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<PropsT, StateT, 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<PropsT, StateT, 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<PropsT, StateT, 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<PropsT, StateT, OutputT>.(E1, E2, E3, E4, E5, E6, E7, E8) -> Unit): (E1, E2, E3, E4, E5, E6, E7, E8) -> Unit


[jvm]
Content
open fun eventHandler(name: () -> String = { “eventHandler” }, update: WorkflowAction.Updater<PropsT, StateT, OutputT>.() -> Unit): () -> Unit
More info
Creates a function which builds a WorkflowAction from the given update function, and immediately passes it to actionSink.


renderChild [jvm]
Content
abstract fun <ChildPropsT, ChildOutputT, ChildRenderingT> renderChild(child: Workflow<ChildPropsT, ChildOutputT, ChildRenderingT>, props: ChildPropsT, key: String = “”, handler: (ChildOutputT) -> WorkflowAction<PropsT, StateT, OutputT>): ChildRenderingT
More info
Ensures child is running as a child of this workflow, and returns the result of its render method.


runningSideEffect [jvm]
Content
abstract fun runningSideEffect(key: String, sideEffect: suspend CoroutineScope.() -> Unit)
More info
Ensures sideEffect is running with the given key.


Properties

Name Summary
actionSink [jvm] abstract val actionSink: Sink<WorkflowAction<PropsT, StateT, OutputT>>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.

Inheritors

Name
StatefulWorkflow
StatelessWorkflow

Extensions

Name Summary
renderChild [jvm]
Content
fun <PropsT, StateT, OutputT, ChildOutputT, ChildRenderingT> BaseRenderContext<PropsT, StateT, OutputT>.renderChild(child: Workflow<Unit, ChildOutputT, ChildRenderingT>, key: String = “”, handler: (ChildOutputT) -> WorkflowAction<PropsT, StateT, OutputT>): ChildRenderingT
More info
Convenience alias of BaseRenderContext.renderChild for workflows that don’t take props.


[jvm]
Content
fun <PropsT, ChildPropsT, StateT, OutputT, ChildRenderingT> BaseRenderContext<PropsT, StateT, OutputT>.renderChild(child: Workflow<ChildPropsT, Nothing, ChildRenderingT>, props: ChildPropsT, key: String = “”): ChildRenderingT
More info
Convenience alias of BaseRenderContext.renderChild for workflows that don’t emit output.


[jvm]
Content
fun <PropsT, StateT, OutputT, ChildRenderingT> BaseRenderContext<PropsT, StateT, OutputT>.renderChild(child: Workflow<Unit, Nothing, ChildRenderingT>, key: String = “”): ChildRenderingT
More info
Convenience alias of BaseRenderContext.renderChild for children that don’t take props or emit output.


runningWorker [jvm]
Content
inline fun <W : Worker<Nothing>, PropsT, StateT, OutputT> BaseRenderContext<PropsT, StateT, OutputT>.runningWorker(worker: W, key: String = “”)
More info
Ensures a Worker that never emits anything is running.


[jvm]
Content
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>)
More info
Ensures worker is running.