Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import com.squareup.workflow.WorkflowAction.Companion.noop
*
* See [renderChild].
*/
interface RenderContext<StateT : Any, in OutputT : Any> {
interface RenderContext<StateT, in OutputT : Any> {

/**
* Given a function that takes an [event][EventT] and can mutate the state or emit an output,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ import kotlinx.coroutines.CoroutineScope
* @see StatelessWorkflow
*/
abstract class StatefulWorkflow<
in InputT : Any,
StateT : Any,
in InputT,
StateT,
out OutputT : Any,
out RenderingT : Any
out RenderingT
> : Workflow<InputT, OutputT, RenderingT> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import com.squareup.workflow.WorkflowAction.Companion.emitOutput
*
* @see StatefulWorkflow
*/
abstract class StatelessWorkflow<InputT : Any, OutputT : Any, RenderingT : Any> :
abstract class StatelessWorkflow<InputT, OutputT : Any, RenderingT> :
Workflow<InputT, OutputT, RenderingT> {

private val statefulWorkflow = object : StatefulWorkflow<InputT, Unit, OutputT, RenderingT>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ package com.squareup.workflow
* @see StatefulWorkflow
* @see StatelessWorkflow
*/
interface Workflow<in InputT : Any, out OutputT : Any, out RenderingT : Any> {
interface Workflow<in InputT, out OutputT : Any, out RenderingT> {

/**
* Provides a [StatefulWorkflow] view of this workflow. Necessary because [StatefulWorkflow] is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.squareup.workflow
* A function that can change the current state of a [Workflow] by returning a new one, and
* also optionally emit an output.
*/
interface WorkflowAction<StateT : Any, out OutputT : Any> : (StateT) -> Pair<StateT, OutputT?> {
interface WorkflowAction<StateT, out OutputT : Any> : (StateT) -> Pair<StateT, OutputT?> {

override operator fun invoke(state: StateT): Pair<StateT, OutputT?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ private val DEFAULT_WORKFLOW_COROUTINE_NAME = CoroutineName("WorkflowHost")
*
* Create these by injecting a [Factory] and calling [run][Factory.run].
*/
interface WorkflowHost<in InputT : Any, out OutputT : Any, out RenderingT : Any> {
interface WorkflowHost<in InputT, out OutputT : Any, out RenderingT> {

/**
* Output from a [WorkflowHost]. Emitted from [WorkflowHost.updates] after every render pass.
*/
data class Update<out OutputT : Any, out RenderingT : Any>(
data class Update<out OutputT : Any, out RenderingT>(
val rendering: RenderingT,
val snapshot: Snapshot,
val output: OutputT? = null
Expand Down Expand Up @@ -82,7 +82,7 @@ interface WorkflowHost<in InputT : Any, out OutputT : Any, out RenderingT : Any>
* @param context The [CoroutineContext] used to run the workflow tree. Added to the [Factory]'s
* context.
*/
fun <InputT : Any, OutputT : Any, RenderingT : Any> run(
fun <InputT, OutputT : Any, RenderingT> run(
workflow: Workflow<InputT, OutputT, RenderingT>,
inputs: ReceiveChannel<InputT>,
snapshot: Snapshot? = null,
Expand All @@ -103,7 +103,7 @@ interface WorkflowHost<in InputT : Any, out OutputT : Any, out RenderingT : Any>
}
}

fun <OutputT : Any, RenderingT : Any> run(
fun <OutputT : Any, RenderingT> run(
workflow: Workflow<Unit, OutputT, RenderingT>,
snapshot: Snapshot? = null,
context: CoroutineContext = EmptyCoroutineContext
Expand All @@ -118,7 +118,7 @@ interface WorkflowHost<in InputT : Any, out OutputT : Any, out RenderingT : Any>
* the testing extension method defined there on your workflow itself.
*/
@TestOnly
fun <InputT : Any, StateT : Any, OutputT : Any, RenderingT : Any> runTestFromState(
fun <InputT, StateT : Any, OutputT : Any, RenderingT> runTestFromState(
workflow: StatefulWorkflow<InputT, StateT, OutputT, RenderingT>,
inputs: ReceiveChannel<InputT>,
initialState: StateT
Expand Down Expand Up @@ -153,7 +153,7 @@ interface WorkflowHost<in InputT : Any, out OutputT : Any, out RenderingT : Any>
* favorite Rx library to map a stream of [InputT]s into [Update]s.
*/
@UseExperimental(InternalCoroutinesApi::class)
suspend fun <InputT : Any, StateT : Any, OutputT : Any, RenderingT : Any> runWorkflowTree(
suspend fun <InputT, StateT, OutputT : Any, RenderingT> runWorkflowTree(
workflow: StatefulWorkflow<InputT, StateT, OutputT, RenderingT>,
inputs: ReceiveChannel<InputT>,
initialSnapshot: Snapshot?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import kotlinx.coroutines.Deferred
*
* @see RealRenderContext
*/
internal data class Behavior<StateT : Any, out OutputT : Any>(
internal data class Behavior<StateT, out OutputT : Any>(
val childCases: List<WorkflowOutputCase<*, *, StateT, OutputT>>,
val workerCases: List<WorkerCase<*, StateT, OutputT>>,
val nextActionFromEvent: Deferred<WorkflowAction<StateT, OutputT>>
Expand All @@ -38,7 +38,7 @@ internal data class Behavior<StateT : Any, out OutputT : Any>(
data class WorkflowOutputCase<
ChildInputT : Any,
ChildOutputT : Any,
ParentStateT : Any,
ParentStateT,
out ParentOutputT : Any
>(
val workflow: Workflow<*, ChildOutputT, *>,
Expand All @@ -52,7 +52,7 @@ internal data class Behavior<StateT : Any, out OutputT : Any>(
}
// @formatter:on

data class WorkerCase<T, StateT : Any, out OutputT : Any>(
data class WorkerCase<T, StateT, out OutputT : Any>(
val worker: Worker<T>,
val key: String,
val handler: (OutputOrFinished<T>) -> WorkflowAction<StateT, OutputT>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import kotlinx.coroutines.CompletableDeferred
/**
* An implementation of [RenderContext] that builds a [Behavior] via [buildBehavior].
*/
internal class RealRenderContext<StateT : Any, OutputT : Any>(
internal class RealRenderContext<StateT, OutputT : Any>(
private val renderer: Renderer<StateT, OutputT>
) : RenderContext<StateT, OutputT> {

interface Renderer<StateT : Any, in OutputT : Any> {
interface Renderer<StateT, in OutputT : Any> {
fun <ChildInputT : Any, ChildOutputT : Any, ChildRenderingT : Any> render(
case: WorkflowOutputCase<ChildInputT, ChildOutputT, StateT, OutputT>,
child: Workflow<ChildInputT, ChildOutputT, ChildRenderingT>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import kotlin.coroutines.CoroutineContext
* Responsible for tracking child workflows, starting them and tearing them down when necessary. Also
* manages restoring children from snapshots.
*/
internal class SubtreeManager<StateT : Any, OutputT : Any>(
internal class SubtreeManager<StateT, OutputT : Any>(
private val contextForChildren: CoroutineContext
) : RealRenderContext.Renderer<StateT, OutputT> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ internal typealias AnyId = WorkflowId<*, *, *>
* Value type that can be used to distinguish between different workflows of different types or
* the same type (in that case using a [name]).
*/
internal data class WorkflowId<in InputT : Any, out OutputT : Any, out RenderingT : Any>
internal data class WorkflowId<in InputT, out OutputT : Any, out RenderingT>
@PublishedApi
internal constructor(
internal val type: KClass<out Workflow<InputT, OutputT, RenderingT>>,
internal val name: String = ""
)

@Suppress("unused")
internal fun <W : Workflow<P, O, R>, P : Any, O : Any, R : Any>
W.id(key: String = ""): WorkflowId<P, O, R> =
internal fun <W : Workflow<I, O, R>, I, O : Any, R>
W.id(key: String = ""): WorkflowId<I, O, R> =
WorkflowId(this::class, key)

internal fun WorkflowId<*, *, *>.toByteString(): ByteString = Buffer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import kotlin.coroutines.CoroutineContext
* @param initialState Allows unit tests to start the node from a given state, instead of calling
* [StatefulWorkflow.initialState].
*/
internal class WorkflowNode<InputT : Any, StateT : Any, OutputT : Any, RenderingT : Any>(
internal class WorkflowNode<InputT, StateT, OutputT : Any, RenderingT>(
val id: WorkflowId<InputT, OutputT, RenderingT>,
workflow: StatefulWorkflow<InputT, StateT, OutputT, RenderingT>,
initialInput: InputT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import kotlin.coroutines.EmptyCoroutineContext
* - [sendInput]
* - Send a new [InputT] to the root workflow.
*/
class WorkflowTester<InputT : Any, OutputT : Any, RenderingT : Any> @TestOnly internal constructor(
class WorkflowTester<InputT, OutputT : Any, RenderingT> @TestOnly internal constructor(
private val inputs: SendChannel<InputT>,
private val host: WorkflowHost<InputT, OutputT, RenderingT>,
context: CoroutineContext
Expand Down Expand Up @@ -191,7 +191,7 @@ class WorkflowTester<InputT : Any, OutputT : Any, RenderingT : Any> @TestOnly in
*/
// @formatter:off
@TestOnly
fun <T, InputT : Any, OutputT : Any, RenderingT : Any>
fun <T, InputT, OutputT : Any, RenderingT>
Workflow<InputT, OutputT, RenderingT>.testFromStart(
input: InputT,
snapshot: Snapshot? = null,
Expand All @@ -209,7 +209,7 @@ fun <T, InputT : Any, OutputT : Any, RenderingT : Any>
* All workflow-related coroutines are cancelled when the block exits.
*/
@TestOnly
fun <T, OutputT : Any, RenderingT : Any> Workflow<Unit, OutputT, RenderingT>.testFromStart(
fun <T, OutputT : Any, RenderingT> Workflow<Unit, OutputT, RenderingT>.testFromStart(
snapshot: Snapshot? = null,
context: CoroutineContext = EmptyCoroutineContext,
block: WorkflowTester<Unit, OutputT, RenderingT>.() -> T
Expand All @@ -224,7 +224,7 @@ fun <T, OutputT : Any, RenderingT : Any> Workflow<Unit, OutputT, RenderingT>.tes
*/
// @formatter:off
@TestOnly
fun <T, InputT : Any, StateT : Any, OutputT : Any, RenderingT : Any>
fun <T, InputT, StateT : Any, OutputT : Any, RenderingT>
StatefulWorkflow<InputT, StateT, OutputT, RenderingT>.testFromState(
input: InputT,
initialState: StateT,
Expand All @@ -245,7 +245,7 @@ fun <T, InputT : Any, StateT : Any, OutputT : Any, RenderingT : Any>
*/
// @formatter:off
@TestOnly
fun <StateT : Any, OutputT : Any, RenderingT : Any>
fun <StateT : Any, OutputT : Any, RenderingT>
StatefulWorkflow<Unit, StateT, OutputT, RenderingT>.testFromState(
initialState: StateT,
context: CoroutineContext = EmptyCoroutineContext,
Expand All @@ -254,7 +254,7 @@ fun <StateT : Any, OutputT : Any, RenderingT : Any>
// @formatter:on

@UseExperimental(InternalCoroutinesApi::class)
private fun <T, I : Any, O : Any, R : Any> test(
private fun <T, I, O : Any, R> test(
testBlock: (WorkflowTester<I, O, R>) -> T,
baseContext: CoroutineContext,
starter: (WorkflowHost.Factory, inputs: Channel<I>) -> WorkflowHost<I, O, R>
Expand Down