Skip to content

Commit f42f446

Browse files
WIP: Exploring Compose Runtime Integration
Is it as simple as key()?
1 parent d1c024c commit f42f446

File tree

34 files changed

+1526
-1405
lines changed

34 files changed

+1526
-1405
lines changed

build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ buildscript {
1010
classpath(libs.kotlin.serialization.gradle.plugin)
1111
classpath(libs.kotlinx.binaryCompatibility.gradle.plugin)
1212
classpath(libs.kotlin.gradle.plugin)
13+
classpath(libs.molecule.gradle.plugin)
1314
classpath(libs.google.ksp)
1415
classpath(libs.ktlint.gradle)
1516
classpath(libs.vanniktech.publish)
@@ -19,6 +20,9 @@ buildscript {
1920
mavenCentral()
2021
gradlePluginPortal()
2122
google()
23+
maven {
24+
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
25+
}
2226
// For binary compatibility validator.
2327
maven { url = uri("https://kotlin.bintray.com/kotlinx") }
2428
}

buildSrc/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ plugins {
77
repositories {
88
mavenCentral()
99
google()
10+
// For molecule SNAPSHOT
11+
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/")}
1012
}
1113

1214
dependencies {

gradle/libs.versions.toml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ targetSdk = "30"
99
androidx-activity = "1.3.0"
1010
androidx-appcompat = "1.3.1"
1111
androidx-benchmark = "1.1.0-rc03"
12-
androidx-compose = "1.1.0-rc01"
13-
androidx-compose-compiler = "1.1.0-rc02"
12+
compose = "1.1.0"
13+
compose-compiler = "1.1.0"
1414
androidx-constraintlayout = "2.1.2"
1515
androidx-core = "1.6.0"
1616
androidx-fragment = "1.3.6"
@@ -49,8 +49,8 @@ kotest = "5.1.0"
4949
kotlin = "1.6.10"
5050

5151
kotlinx-binary-compatibility = "0.6.0"
52-
kotlinx-coroutines = "1.5.1"
53-
# The 1.5.1 test artifact is jvm-only. The commonTest module should use 1.6.1.
52+
kotlinx-coroutines = "1.5.2"
53+
# The 1.5.2 test artifact is jvm-only. The commonTest module should use 1.6.1.
5454
kotlinx-coroutines-test-common = "1.6.1"
5555
kotlinx-serialization-json = "1.3.2"
5656
kotlinx-benchmark = "0.4.2"
@@ -64,6 +64,9 @@ mockito-core = "3.3.3"
6464
mockito-kotlin = "3.2.0"
6565

6666
mockk = "1.11.0"
67+
68+
molecule = "0.3.0-SNAPSHOT"
69+
6770
robolectric = "4.6.1"
6871

6972
rxjava2-android = "2.1.1"
@@ -100,8 +103,12 @@ kotlinx-benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "kot
100103
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
101104
mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktech-publish" }
102105

106+
molecule = { id = "app.cash.molecule", version.ref = "molecule"}
107+
103108
[libraries]
104109

110+
molecule-gradle-plugin = { module = "app.cash.molecule:molecule-gradle-plugin", version.ref = "molecule"}
111+
105112
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "androidTools" }
106113

107114
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
@@ -112,13 +119,16 @@ androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "a
112119

113120
androidx-macro-benchmark = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "androidx-benchmark" }
114121

115-
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose" }
122+
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" }
123+
124+
androidx-compose-material = { module = "androidx.compose.material:material", version.ref = "compose" }
116125

117-
androidx-compose-material = { module = "androidx.compose.material:material", version.ref = "androidx-compose" }
126+
androidx-compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
127+
androidx-compose-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "compose" }
128+
androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
118129

119-
androidx-compose-ui = { module = "androidx.compose.ui:ui", version.ref = "androidx-compose" }
120-
androidx-compose-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "androidx-compose" }
121-
androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "androidx-compose" }
130+
compose-runtime = { module = "org.jetbrains.compose.runtime:runtime", version.ref = "compose"}
131+
compose-compiler = { module = "org.jetbrains.compose.compiler:compiler", version.ref = "compose"}
122132

123133
androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "androidx-constraintlayout" }
124134

@@ -203,6 +213,8 @@ mockito-kotlin = { module = "org.mockito.kotlin:mockito-kotlin", version.ref = "
203213

204214
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
205215

216+
molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "molecule"}
217+
206218
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
207219

208220
rxjava2-rxandroid = { module = "io.reactivex.rxjava2:rxandroid", version.ref = "rxjava2-android" }

samples/compose-samples/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ android {
1414
compose = true
1515
}
1616
composeOptions {
17-
kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get()
17+
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
1818
}
1919
}
2020

settings.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pluginManagement {
99
google()
1010
// For binary compatibility validator.
1111
maven { url = uri("https://kotlin.bintray.com/kotlinx") }
12+
// For molecule SNAPSHOT
13+
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/")}
1214
}
1315
}
1416

@@ -29,6 +31,8 @@ dependencyResolutionManagement {
2931
repositories {
3032
mavenCentral()
3133
google()
34+
// For molecule SNAPSHOT
35+
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/")}
3236
// See androidx.dev (can use this for Snapshot builds of AndroidX)
3337
// maven { url = java.net.URI.create("https://androidx.dev/snapshots/builds/8224905/artifacts/repository") }
3438
}

workflow-core/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ apply(from = rootProject.file(".buildscript/configure-maven-publish.gradle"))
77

88
kotlin {
99
jvm { withJava() }
10-
ios()
10+
// ios()
1111

1212
sourceSets {
1313
all {
@@ -19,6 +19,7 @@ kotlin {
1919
dependencies {
2020
api(libs.kotlin.jdk6)
2121
api(libs.kotlinx.coroutines.core)
22+
api(libs.compose.runtime)
2223
// For Snapshot.
2324
api(libs.squareup.okio)
2425
}
@@ -28,6 +29,7 @@ kotlin {
2829
implementation(libs.kotlinx.atomicfu)
2930
implementation(libs.kotlinx.coroutines.test.common)
3031
implementation(libs.kotlin.test.jdk)
32+
implementation(libs.molecule.runtime)
3133
}
3234
}
3335
}

workflow-core/src/commonMain/kotlin/com/squareup/workflow1/BaseRenderContext.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package com.squareup.workflow1
66

7+
import androidx.compose.runtime.Composable
78
import com.squareup.workflow1.WorkflowAction.Companion.noAction
89
import kotlinx.coroutines.CoroutineScope
910
import kotlin.jvm.JvmMultifileClass
@@ -71,6 +72,7 @@ public interface BaseRenderContext<out PropsT, StateT, in OutputT> {
7172
* @param key An optional string key that is used to distinguish between workflows of the same
7273
* type.
7374
*/
75+
@Composable
7476
public fun <ChildPropsT, ChildOutputT, ChildRenderingT> renderChild(
7577
child: Workflow<ChildPropsT, ChildOutputT, ChildRenderingT>,
7678
props: ChildPropsT,
@@ -217,6 +219,7 @@ public interface BaseRenderContext<out PropsT, StateT, in OutputT> {
217219
/**
218220
* Convenience alias of [BaseRenderContext.renderChild] for workflows that don't take props.
219221
*/
222+
@Composable
220223
public fun <PropsT, StateT, OutputT, ChildOutputT, ChildRenderingT>
221224
BaseRenderContext<PropsT, StateT, OutputT>.renderChild(
222225
child: Workflow<Unit, ChildOutputT, ChildRenderingT>,
@@ -226,6 +229,7 @@ BaseRenderContext<PropsT, StateT, OutputT>.renderChild(
226229
/**
227230
* Convenience alias of [BaseRenderContext.renderChild] for workflows that don't emit output.
228231
*/
232+
@Composable
229233
public fun <PropsT, ChildPropsT, StateT, OutputT, ChildRenderingT>
230234
BaseRenderContext<PropsT, StateT, OutputT>.renderChild(
231235
child: Workflow<ChildPropsT, Nothing, ChildRenderingT>,
@@ -236,6 +240,7 @@ BaseRenderContext<PropsT, StateT, OutputT>.renderChild(
236240
* Convenience alias of [BaseRenderContext.renderChild] for children that don't take props or emit
237241
* output.
238242
*/
243+
@Composable
239244
public fun <PropsT, StateT, OutputT, ChildRenderingT>
240245
BaseRenderContext<PropsT, StateT, OutputT>.renderChild(
241246
child: Workflow<Unit, Nothing, ChildRenderingT>,

workflow-core/src/commonMain/kotlin/com/squareup/workflow1/StatefulWorkflow.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package com.squareup.workflow1
66

7+
import androidx.compose.runtime.Composable
78
import com.squareup.workflow1.StatefulWorkflow.RenderContext
89
import com.squareup.workflow1.WorkflowAction.Companion.toString
910
import kotlin.jvm.JvmMultifileClass
@@ -123,6 +124,7 @@ public abstract class StatefulWorkflow<
123124
* _† This method is guaranteed to be called *at least* once for every state, but may be called
124125
* multiple times. Allowing this method to be invoked multiple times makes the internals simpler._
125126
*/
127+
@Composable
126128
public abstract fun render(
127129
renderProps: PropsT,
128130
renderState: StateT,
@@ -191,6 +193,7 @@ public inline fun <PropsT, StateT, OutputT, RenderingT> Workflow.Companion.state
191193
state: StateT
192194
): StateT = onPropsChanged(old, new, state)
193195

196+
@Composable
194197
override fun render(
195198
renderProps: PropsT,
196199
renderState: StateT,

workflow-core/src/commonMain/kotlin/com/squareup/workflow1/StatelessWorkflow.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package com.squareup.workflow1
55

6+
import androidx.compose.runtime.Composable
67
import kotlin.jvm.JvmMultifileClass
78
import kotlin.jvm.JvmName
89

@@ -52,6 +53,7 @@ public abstract class StatelessWorkflow<in PropsT, out OutputT, out RenderingT>
5253
* blocks the current thread. It may be called multiple times for the same state. It must do all its
5354
* work by calling methods on [context].
5455
*/
56+
@Composable
5557
public abstract fun render(
5658
renderProps: PropsT,
5759
context: RenderContext
@@ -90,6 +92,7 @@ public inline fun <PropsT, OutputT, RenderingT> Workflow.Companion.stateless(
9092
crossinline render: BaseRenderContext<PropsT, Nothing, OutputT>.(props: PropsT) -> RenderingT
9193
): Workflow<PropsT, OutputT, RenderingT> =
9294
object : StatelessWorkflow<PropsT, OutputT, RenderingT>() {
95+
@Composable
9396
override fun render(
9497
renderProps: PropsT,
9598
context: RenderContext

workflow-core/src/commonMain/kotlin/com/squareup/workflow1/WorkerWorkflow.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package com.squareup.workflow1
55

6+
import androidx.compose.runtime.Composable
67
import kotlinx.coroutines.CoroutineName
78
import kotlinx.coroutines.flow.Flow
89
import kotlinx.coroutines.withContext
@@ -48,6 +49,7 @@ internal class WorkerWorkflow<OutputT>(
4849
state: Int
4950
): Int = if (!old.doesSameWorkAs(new)) state + 1 else state
5051

52+
@Composable
5153
override fun render(
5254
renderProps: Worker<OutputT>,
5355
renderState: Int,

0 commit comments

Comments
 (0)