Package-level declarations

Types

Link copied to clipboard
class ActionApplied<out OutputT> @JvmOverloads constructor(val output: WorkflowOutput<OutputT>?, val stateChanged: Boolean = false) : ActionProcessingResult

Result of applying an action.

Link copied to clipboard

An ActionProcessingResult is any possible outcome after the runtime does a loop of processing.

Link copied to clipboard
Link copied to clipboard

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

Link copied to clipboard
interface IdCacheable

If your Workflow caches its WorkflowIdentifier (to avoid frequent lookups) then implement this interface. Note that StatefulWorkflow and StatelessWorkflow already implement this, so you only need to do so if you do not extend one of those classes.

Link copied to clipboard

Optional interface that Workflows should implement if they need the runtime to consider their identity to include a child workflow's identity. Two ImpostorWorkflows with the same concrete class, but different realIdentifiers will be considered different workflows by the runtime.

Link copied to clipboard
abstract class LifecycleWorker : Worker<Nothing>

Worker that performs some action when the worker is started and/or stopped.

Link copied to clipboard
Link copied to clipboard

An extension of StatefulWorkflow that gives initialState a CoroutineScope that corresponds with the lifetime of session driven by this Workflow.

Link copied to clipboard
fun interface Sink<in T>

An object that receives values (commonly events or WorkflowAction). BaseRenderContext.actionSink implements this interface.

Link copied to clipboard
class Snapshot

A lazy wrapper of ByteString. Allows Workflows to capture their state frequently, without worrying about performing unnecessary serialization work.

Link copied to clipboard

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.

Link copied to clipboard

Minimal implementation of Workflow that maintains no state of its own.

Link copied to clipboard
interface Worker<out OutputT>

Represents a unit of asynchronous work that can have zero, one, or multiple outputs.

Link copied to clipboard
interface Workflow<in PropsT, out OutputT, out RenderingT>

A composable, optionally-stateful object that can handle events, delegate to children, subscribe to arbitrary asynchronous events from the outside world.

Link copied to clipboard
abstract class WorkflowAction<in PropsT, StateT, out OutputT>

An atomic operation that updates the state of a Workflow, and also optionally emits an output.

Link copied to clipboard

This is used to mark new core Workflow API that is still considered experimental.

Link copied to clipboard

Represents a Workflow's "identity" and is used by the runtime to determine whether a workflow is the same as one that was rendered in a previous render pass, in which case its state should be re-used; or if it's a new workflow and needs to be started.

Link copied to clipboard

Represents a subset of KAnnotatedElement, namely KClass or KType. Used by the runtime to determine whether a WorkflowIdentifier, and thus the Workflow it identifies, is serializable or not via the Snapshot mechanism.

Link copied to clipboard
class WorkflowOutput<out OutputT>(val value: OutputT)

Box around a potentially nullable OutputT

Properties

Link copied to clipboard

The computed WorkflowIdentifier for this Workflow. Any IdCacheable Workflow should call this and then store the value in the cachedIdentifier property so as to prevent the extra work needed to create the WorkflowIdentifier and look up the class name each time.

Link copied to clipboard

The WorkflowIdentifier that identifies this Workflow.

Link copied to clipboard
@get:TestOnly
val KClass<out Workflow<*, *, *>>.workflowIdentifier: WorkflowIdentifier

The WorkflowIdentifier that identifies the workflow this KClass represents.

Functions

Link copied to clipboard

Creates a WorkflowAction from the apply lambda. The returned object will include the string returned from name in its toString.

Link copied to clipboard
Link copied to clipboard
inline fun <OutputT> Flow<OutputT>.asWorker(): Worker<OutputT>

Returns a Worker that will, when performed, emit whatever this Flow receives.

Link copied to clipboard
fun <T1, T2> Sink<T1>.contraMap(transform: (T2) -> T1): Sink<T2>

Generates a new sink of type T2.

Link copied to clipboard
Link copied to clipboard
inline fun <T> ByteString.parse(block: (BufferedSource) -> T): T

Runs block with a BufferedSource that will read from this ByteString.

Link copied to clipboard
fun BufferedSource.readBooleanFromInt(): Boolean
Link copied to clipboard
fun BufferedSource.readByteStringWithLength(): ByteString
Link copied to clipboard
inline fun <T : Enum<T>> BufferedSource.readEnumByOrdinal(): T
Link copied to clipboard
fun BufferedSource.readFloat(): Float
Link copied to clipboard
inline fun <T> BufferedSource.readList(reader: BufferedSource.() -> T): List<T>
Link copied to clipboard
fun <T : Any> BufferedSource.readNullable(reader: BufferedSource.() -> T): T?
Link copied to clipboard
inline fun <T : Enum<T>> BufferedSource.readOptionalEnumByOrdinal(): T?
Link copied to clipboard
fun BufferedSource.readOptionalUtf8WithLength(): String?
Link copied to clipboard
fun BufferedSource.readUtf8WithLength(): String
Link copied to clipboard
Link copied to clipboard

Returns a workflow that does nothing but echo the given rendering. Handy for testing.

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

Link copied to clipboard
inline fun <StateT, OutputT, RenderingT> Workflow.Companion.sessionWorkflow(crossinline initialState: (CoroutineScope) -> StateT, crossinline render: BaseRenderContext<Unit, StateT, OutputT>.(state: StateT) -> RenderingT): SessionWorkflow<Unit, StateT, OutputT, RenderingT>

Returns a SessionWorkflow, with no props, implemented via the given function.

inline fun <PropsT, StateT, OutputT, RenderingT> Workflow.Companion.sessionWorkflow(crossinline initialState: (PropsT, CoroutineScope) -> StateT, crossinline render: BaseRenderContext<PropsT, StateT, OutputT>.(props: PropsT, state: StateT) -> RenderingT, crossinline onPropsChanged: (old: PropsT, new: PropsT, state: StateT) -> StateT = { _, _, state -> state }): SessionWorkflow<PropsT, StateT, OutputT, RenderingT>
inline fun <PropsT, StateT, OutputT, RenderingT> Workflow.Companion.sessionWorkflow(crossinline initialState: (PropsT, Snapshot?, CoroutineScope) -> StateT, crossinline render: BaseRenderContext<PropsT, StateT, OutputT>.(props: PropsT, state: StateT) -> RenderingT, crossinline snapshot: (StateT) -> Snapshot?, crossinline onPropsChanged: (old: PropsT, new: PropsT, state: StateT) -> StateT = { _, _, state -> state }): SessionWorkflow<PropsT, StateT, OutputT, RenderingT>

Returns a SessionWorkflow implemented via the given functions.

inline fun <StateT, OutputT, RenderingT> Workflow.Companion.sessionWorkflow(crossinline initialState: (Snapshot?, CoroutineScope) -> StateT, crossinline render: BaseRenderContext<Unit, StateT, OutputT>.(state: StateT) -> RenderingT, crossinline snapshot: (StateT) -> Snapshot?): SessionWorkflow<Unit, StateT, OutputT, RenderingT>

Returns a SessionWorkflow, with no props, implemented via the given functions.

Link copied to clipboard

Returns a stateful Workflow, with no props, implemented via the given function.

inline fun <PropsT, StateT, OutputT, RenderingT> Workflow.Companion.stateful(crossinline initialState: (PropsT) -> StateT, crossinline render: BaseRenderContext<PropsT, StateT, OutputT>.(props: PropsT, state: StateT) -> RenderingT, crossinline onPropsChanged: (old: PropsT, new: PropsT, state: StateT) -> StateT = { _, _, state -> state }): StatefulWorkflow<PropsT, StateT, OutputT, RenderingT>
inline fun <PropsT, StateT, OutputT, RenderingT> Workflow.Companion.stateful(crossinline initialState: (PropsT, Snapshot?) -> StateT, crossinline render: BaseRenderContext<PropsT, StateT, OutputT>.(props: PropsT, state: StateT) -> RenderingT, crossinline snapshot: (StateT) -> Snapshot?, crossinline onPropsChanged: (old: PropsT, new: PropsT, state: StateT) -> StateT = { _, _, state -> state }): StatefulWorkflow<PropsT, StateT, OutputT, RenderingT>

Returns a stateful Workflow implemented via the given functions.

inline fun <StateT, OutputT, RenderingT> Workflow.Companion.stateful(crossinline initialState: (Snapshot?) -> StateT, crossinline render: BaseRenderContext<Unit, StateT, OutputT>.(state: StateT) -> RenderingT, crossinline snapshot: (StateT) -> Snapshot?): StatefulWorkflow<Unit, StateT, OutputT, RenderingT>

Returns a stateful Workflow, with no props, implemented via the given functions.

Link copied to clipboard

Returns a stateless Workflow via the given render function.

Link copied to clipboard
fun <T, R> Worker<T>.transform(transform: (Flow<T>) -> Flow<R>): Worker<R>

Returns a Worker that transforms this Worker's Flow by calling transform.

Link copied to clipboard

Creates a WorkflowIdentifier that is not capable of being snapshotted and will cause any ImpostorWorkflow workflow identified by it to also not be snapshotted.

Link copied to clipboard
fun BufferedSink.writeBooleanAsInt(bool: Boolean): BufferedSink
Link copied to clipboard
fun BufferedSink.writeByteStringWithLength(bytes: ByteString): BufferedSink
Link copied to clipboard
fun <T : Enum<T>> BufferedSink.writeEnumByOrdinal(enumVal: T): BufferedSink
Link copied to clipboard
fun BufferedSink.writeFloat(float: Float): BufferedSink
Link copied to clipboard
inline fun <T> BufferedSink.writeList(values: List<T>, writer: BufferedSink.(T) -> Unit): BufferedSink
Link copied to clipboard
fun <T : Any> BufferedSink.writeNullable(obj: T?, writer: BufferedSink.(T) -> Unit): BufferedSink
Link copied to clipboard
fun <T : Enum<T>> BufferedSink.writeOptionalEnumByOrdinal(enumVal: T?): BufferedSink
Link copied to clipboard
fun BufferedSink.writeOptionalUtf8WithLength(str: String?): BufferedSink
Link copied to clipboard
fun BufferedSink.writeUtf8WithLength(str: String): BufferedSink