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
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ kotlin = "1.6.10"

kotlinx-binary-compatibility = "0.6.0"
kotlinx-coroutines = "1.5.1"
# The 1.5.1 test artifact is jvm-only. The commonTest module should use 1.6.1.
kotlinx-coroutines-test-common = "1.6.1"
kotlinx-serialization-json = "1.3.2"
kotlinx-benchmark = "0.4.2"
kotlinx-atomicfu = "0.17.2"

ktlint = "10.3.0"
material = "1.3.0"
Expand Down Expand Up @@ -184,9 +187,11 @@ kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutine
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-rx2 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-rx2", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-test-common = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines-test-common" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization-json" }
kotlinx-benchmark-gradle-plugin = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-plugin", version.ref = "kotlinx-benchmark" }
kotlinx-benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "kotlinx-benchmark" }
kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "kotlinx-atomicfu" }

ktlint-gradle = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "ktlint" }

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ gradleEnterprise {

@Suppress("UnstableApiUsage")
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No big deal.

repositories {
mavenCentral()
google()
Expand Down
45 changes: 41 additions & 4 deletions workflow-core/api/workflow-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ public final class com/squareup/workflow1/TypedWorker : com/squareup/workflow1/W
public fun toString ()Ljava/lang/String;
}

public final class com/squareup/workflow1/Void {
}

public abstract interface class com/squareup/workflow1/Worker {
public static final field Companion Lcom/squareup/workflow1/Worker$Companion;
public abstract fun doesSameWorkAs (Lcom/squareup/workflow1/Worker;)Z
Expand Down Expand Up @@ -228,10 +231,10 @@ public final class com/squareup/workflow1/WorkflowAction$Updater {

public final class com/squareup/workflow1/WorkflowIdentifier {
public static final field Companion Lcom/squareup/workflow1/WorkflowIdentifier$Companion;
public fun <init> (Lkotlin/reflect/KAnnotatedElement;Lcom/squareup/workflow1/WorkflowIdentifier;Lkotlin/jvm/functions/Function0;)V
public synthetic fun <init> (Lkotlin/reflect/KAnnotatedElement;Lcom/squareup/workflow1/WorkflowIdentifier;Lkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lcom/squareup/workflow1/WorkflowIdentifierType;Lcom/squareup/workflow1/WorkflowIdentifier;Lkotlin/jvm/functions/Function0;)V
public synthetic fun <init> (Lcom/squareup/workflow1/WorkflowIdentifierType;Lcom/squareup/workflow1/WorkflowIdentifier;Lkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun equals (Ljava/lang/Object;)Z
public final fun getRealIdentifierType ()Lkotlin/reflect/KAnnotatedElement;
public final fun getRealIdentifierType ()Lcom/squareup/workflow1/WorkflowIdentifierType;
public fun hashCode ()I
public final fun toByteStringOrNull ()Lokio/ByteString;
public fun toString ()Ljava/lang/String;
Expand All @@ -241,6 +244,41 @@ public final class com/squareup/workflow1/WorkflowIdentifier$Companion {
public final fun parse (Lokio/ByteString;)Lcom/squareup/workflow1/WorkflowIdentifier;
}

public final class com/squareup/workflow1/WorkflowIdentifierExKt {
public static final fun getWorkflowIdentifier (Lkotlin/reflect/KClass;)Lcom/squareup/workflow1/WorkflowIdentifier;
}

public abstract class com/squareup/workflow1/WorkflowIdentifierType {
public abstract fun getTypeName ()Ljava/lang/String;
}

public final class com/squareup/workflow1/WorkflowIdentifierType$Snapshottable : com/squareup/workflow1/WorkflowIdentifierType {
public fun <init> (Ljava/lang/String;Lkotlin/reflect/KClass;)V
public synthetic fun <init> (Ljava/lang/String;Lkotlin/reflect/KClass;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lkotlin/reflect/KClass;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Lkotlin/reflect/KClass;
public final fun copy (Ljava/lang/String;Lkotlin/reflect/KClass;)Lcom/squareup/workflow1/WorkflowIdentifierType$Snapshottable;
public static synthetic fun copy$default (Lcom/squareup/workflow1/WorkflowIdentifierType$Snapshottable;Ljava/lang/String;Lkotlin/reflect/KClass;ILjava/lang/Object;)Lcom/squareup/workflow1/WorkflowIdentifierType$Snapshottable;
public fun equals (Ljava/lang/Object;)Z
public final fun getKClass ()Lkotlin/reflect/KClass;
public fun getTypeName ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/squareup/workflow1/WorkflowIdentifierType$Unsnapshottable : com/squareup/workflow1/WorkflowIdentifierType {
public fun <init> (Lkotlin/reflect/KType;)V
public final fun component1 ()Lkotlin/reflect/KType;
public final fun copy (Lkotlin/reflect/KType;)Lcom/squareup/workflow1/WorkflowIdentifierType$Unsnapshottable;
public static synthetic fun copy$default (Lcom/squareup/workflow1/WorkflowIdentifierType$Unsnapshottable;Lkotlin/reflect/KType;ILjava/lang/Object;)Lcom/squareup/workflow1/WorkflowIdentifierType$Unsnapshottable;
public fun equals (Ljava/lang/Object;)Z
public final fun getKType ()Lkotlin/reflect/KType;
public fun getTypeName ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/squareup/workflow1/WorkflowOutput {
public fun <init> (Ljava/lang/Object;)V
public fun equals (Ljava/lang/Object;)Z
Expand All @@ -266,7 +304,6 @@ public final class com/squareup/workflow1/Workflows {
public static final fun collectToSink (Lkotlinx/coroutines/flow/Flow;Lcom/squareup/workflow1/Sink;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun contraMap (Lcom/squareup/workflow1/Sink;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/Sink;
public static final fun getIdentifier (Lcom/squareup/workflow1/Workflow;)Lcom/squareup/workflow1/WorkflowIdentifier;
public static final fun getWorkflowIdentifier (Lkotlin/reflect/KClass;)Lcom/squareup/workflow1/WorkflowIdentifier;
public static final fun mapRendering (Lcom/squareup/workflow1/Workflow;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/Workflow;
public static final fun renderChild (Lcom/squareup/workflow1/BaseRenderContext;Lcom/squareup/workflow1/Workflow;Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;
public static final fun renderChild (Lcom/squareup/workflow1/BaseRenderContext;Lcom/squareup/workflow1/Workflow;Ljava/lang/String;)Ljava/lang/Object;
Expand Down
15 changes: 10 additions & 5 deletions workflow-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@ apply(from = rootProject.file(".buildscript/configure-maven-publish.gradle"))

kotlin {
jvm { withJava() }
ios()

sourceSets {
val jvmMain by getting {
all {
languageSettings.apply {
optIn("kotlin.RequiresOptIn")
}
}
val commonMain by getting {
dependencies {
compileOnly(libs.jetbrains.annotations)

api(libs.kotlin.jdk6)
api(libs.kotlinx.coroutines.core)
// For Snapshot.
api(libs.squareup.okio)
}
}
val jvmTest by getting {
val commonTest by getting {
dependencies {
implementation(libs.kotlinx.coroutines.test)
implementation(libs.kotlinx.atomicfu)
implementation(libs.kotlinx.coroutines.test.common)
implementation(libs.kotlin.test.jdk)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package com.squareup.workflow1

import com.squareup.workflow1.WorkflowAction.Companion.noAction
import kotlinx.coroutines.CoroutineScope
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName
import kotlin.reflect.KType
import kotlin.reflect.typeOf

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

package com.squareup.workflow1

import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
* Optional interface that [Workflow]s should implement if they need the runtime to consider their
* identity to include a child workflow's identity. Two [ImpostorWorkflow]s with the same concrete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package com.squareup.workflow1
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
* [Worker] that performs some action when the worker is started and/or stopped.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlin.coroutines.resume
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
* An object that receives values (commonly events or [WorkflowAction]).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import okio.BufferedSink
import okio.BufferedSource
import okio.ByteString
import okio.ByteString.Companion.encodeUtf8
import java.lang.Float.floatToRawIntBits
import java.lang.Float.intBitsToFloat
import kotlin.jvm.JvmName
import kotlin.jvm.JvmStatic

/**
* A lazy wrapper of [ByteString]. Allows [Workflow]s to capture their state frequently, without
Expand Down Expand Up @@ -93,9 +93,9 @@ public fun BufferedSink.writeBooleanAsInt(bool: Boolean): BufferedSink =

public fun BufferedSource.readBooleanFromInt(): Boolean = readInt() == 1

public fun BufferedSink.writeFloat(float: Float): BufferedSink = writeInt(floatToRawIntBits(float))
public fun BufferedSink.writeFloat(float: Float): BufferedSink = writeInt(float.toRawBits())

public fun BufferedSource.readFloat(): Float = intBitsToFloat(readInt())
public fun BufferedSource.readFloat(): Float = Float.fromBits(readInt())

public fun BufferedSink.writeUtf8WithLength(str: String): BufferedSink {
return writeByteStringWithLength(str.encodeUtf8())
Expand Down Expand Up @@ -130,7 +130,7 @@ public fun <T : Enum<T>> BufferedSink.writeOptionalEnumByOrdinal(enumVal: T?): B
}

public inline fun <reified T : Enum<T>> BufferedSource.readEnumByOrdinal(): T {
return T::class.java.enumConstants[readInt()]
return enumValues<T>()[readInt()]
}

public fun <T : Enum<T>> BufferedSink.writeEnumByOrdinal(enumVal: T): BufferedSink {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package com.squareup.workflow1

import com.squareup.workflow1.StatefulWorkflow.RenderContext
import com.squareup.workflow1.WorkflowAction.Companion.toString
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
* A composable, stateful object that can [handle events][RenderContext.actionSink],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

package com.squareup.workflow1

import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
* Minimal implementation of [Workflow] that maintains no state of its own.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.squareup.workflow1

/**
* [Nothing] cannot be used as a reified type so we have duplicated
* it here to avoid adding a dependency on kotlin.reflect.
*/
internal class Void private constructor()
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flow
import kotlin.experimental.ExperimentalTypeInference
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName
import kotlin.reflect.KType
import kotlin.reflect.typeOf

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package com.squareup.workflow1
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName
import kotlin.reflect.KType

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

package com.squareup.workflow1

import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
* A composable, optionally-stateful object that can [handle events][BaseRenderContext.actionSink],
* [delegate to children][BaseRenderContext.renderChild],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package com.squareup.workflow1

import com.squareup.workflow1.WorkflowAction.Companion.toString
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
* An atomic operation that updates the state of a [Workflow], and also optionally emits an output.
Expand Down
Loading