Skip to content

workflow-core

workflow-core / com.squareup.workflow

Package com.squareup.workflow

Types

Name Summary
LifecycleWorker abstract class LifecycleWorker :Worker<Nothing>
Worker that performs some action when the worker is started and/or stopped.
RenderContext interface RenderContext<StateT, in OutputT :Any>
Facilities for a Workflow to interact with other Workflows and the outside world from inside a render function.
Sink interface Sink<T>
An object that receives values (commonly events or WorkflowAction). Use RenderContext.makeActionSink to create instances.
Snapshot class Snapshot
A lazy wrapper of ByteString. Allows Workflows to capture their state frequently, without worrying about performing unnecessary serialization work.
StatefulWorkflow abstract class StatefulWorkflow<in PropsT, StateT, out OutputT :Any, out RenderingT> :Workflow<PropsT,OutputT,RenderingT>
A composable, stateful object that can handle events, delegate to children, subscribe to arbitrary asynchronous events from the outside world, and be saved to a serialized form to be restored later.
StatelessWorkflow abstract class StatelessWorkflow<PropsT, OutputT :Any, RenderingT> :Workflow<PropsT,OutputT,RenderingT>
Minimal implementation of Workflow that maintains no state of its own.
Worker interface Worker<out T>
Represents a unit of asynchronous work that can have zero, one, or multiple outputs.
Workflow interface Workflow<in PropsT, out OutputT :Any, out RenderingT>
A composable, optionally-stateful object that can handle events, delegate to children, subscribe to arbitrary asynchronous events from the outside world.
WorkflowAction interface WorkflowAction<StateT, out OutputT :Any>
A function that can change the current state of a Workflow by returning a new one, and also optionally emit an output.

Annotations

Name Summary
VeryExperimentalWorkflow annotation class VeryExperimentalWorkflow
Marks Workflow APIs that are extremely likely to change in future versions, rely themselves on other unstable, experimental APIs, and SHOULD NOT be used in production code. Proceed with caution, and be ready to have the rug pulled out from under you.

Extensions for External Classes

Name Summary
kotlinx.coroutines.channels.BroadcastChannel
kotlinx.coroutines.channels.ReceiveChannel
kotlinx.coroutines.Deferred
kotlinx.coroutines.flow.Flow
okio.BufferedSink
okio.BufferedSource
okio.ByteString

Functions

Name Summary
applyTo fun <StateT, OutputT :Any>WorkflowAction<StateT,OutputT>.applyTo(state:StateT):Pair<StateT,OutputT?>
contraMap fun <T1, T2>Sink<T1>.contraMap(transform: (T2) ->T1):Sink<T2>
Generates a new sink of type T2.
invoke operator fun EventHandler<Unit>.invoke():Unit
EventHandlers of type Unit are effectively no-arg functions, so this override lets you invoke them without passing the Unit argument.
makeEventSink fun <EventT, StateT, OutputT :Any>RenderContext<StateT,OutputT>.makeEventSink(block:WorkflowAction.Mutator<StateT>.(EventT) ->OutputT?):Sink<EventT>
Alternative to RenderContext.makeActionSink that allows externally defined event types to be mapped to anonymous WorkflowActions.
mapRendering fun <PropsT, OutputT :Any, FromRenderingT, ToRenderingT>Workflow<PropsT,OutputT,FromRenderingT>.mapRendering(transform: (FromRenderingT) ->ToRenderingT):Workflow<PropsT,OutputT,ToRenderingT>
Uses the given function to transform a Workflow that renders FromRenderingT to one renders ToRenderingT,
renderChild fun <StateT, OutputT :Any, ChildOutputT :Any, ChildRenderingT>RenderContext<StateT,OutputT>.renderChild(child:Workflow<Unit,ChildOutputT,ChildRenderingT>, key:String= "", handler: (ChildOutputT) ->WorkflowAction<StateT,OutputT>):ChildRenderingT
Convenience alias of RenderContext.renderChild for workflows that don’t take input.fun <PropsT, StateT, OutputT :Any, ChildRenderingT>RenderContext<StateT,OutputT>.renderChild(child:Workflow<PropsT,Nothing,ChildRenderingT>, input:PropsT, key:String= ""):ChildRenderingT
fun <StateT, OutputT :Any, ChildRenderingT>RenderContext<StateT,OutputT>.renderChild(child:Workflow<Unit,Nothing,ChildRenderingT>, key:String= ""):ChildRenderingT
Convenience alias of RenderContext.renderChild for workflows that don’t take input or emit output.
runningWorker fun <StateT, OutputT :Any, T>RenderContext<StateT,OutputT>.runningWorker(worker:Worker<T>, key:String= "", handler: (T) ->WorkflowAction<StateT,OutputT>):Unit
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).fun <StateT, OutputT :Any>RenderContext<StateT,OutputT>.runningWorker(worker:Worker<Nothing>, key:String= ""):Unit
Ensures a Worker that never emits anything is running. Since worker can’t emit anything, it can’t trigger any WorkflowActions.
transform fun <T, R>Worker<T>.transform(key:String= "", transform: (Flow<T>) -> Flow<R>):Worker<R>
Returns a Worker that transforms this Worker‘s Flow by calling transform.

Companion Object Functions

Name Summary
rendering fun <OutputT :Any, RenderingT> Workflow.Companion.rendering(rendering:RenderingT):Workflow<Unit,OutputT,RenderingT>
Returns a workflow that does nothing but echo the given rendering. Handy for testing.
stateful fun <PropsT, StateT, OutputT :Any, RenderingT> Workflow.Companion.stateful(initialState: (PropsT,Snapshot?) ->StateT, render:RenderContext<StateT,OutputT>.(props:PropsT, state:StateT) ->RenderingT, snapshot: (StateT) ->Snapshot, onPropsChanged: (old:PropsT, new:PropsT, state:StateT) ->StateT= { _, _, state -> state }):StatefulWorkflow<PropsT,StateT,OutputT,RenderingT>
fun <PropsT, StateT, OutputT :Any, RenderingT> Workflow.Companion.stateful(initialState: (PropsT) ->StateT, render:RenderContext<StateT,OutputT>.(props:PropsT, state:StateT) ->RenderingT, onPropsChanged: (old:PropsT, new:PropsT, state:StateT) ->StateT= { _, _, state -> state }):StatefulWorkflow<PropsT,StateT,OutputT,RenderingT>
Returns a stateful Workflow implemented via the given functions.fun <StateT, OutputT :Any, RenderingT> Workflow.Companion.stateful(initialState: (Snapshot?) ->StateT, render:RenderContext<StateT,OutputT>.(state:StateT) ->RenderingT, snapshot: (StateT) ->Snapshot):StatefulWorkflow<Unit,StateT,OutputT,RenderingT>
Returns a stateful Workflow, with no props, implemented via the given functions.fun <StateT, OutputT :Any, RenderingT> Workflow.Companion.stateful(initialState:StateT, render:RenderContext<StateT,OutputT>.(state:StateT) ->RenderingT):StatefulWorkflow<Unit,StateT,OutputT,RenderingT>
Returns a stateful Workflow, with no props, implemented via the given function.
stateless fun <PropsT, OutputT :Any, RenderingT> Workflow.Companion.stateless(render:RenderContext<Nothing,OutputT>.(props:PropsT) ->RenderingT):Workflow<PropsT,OutputT,RenderingT>
Returns a stateless Workflow via the given render function.