Skip to content

Commit defbde1

Browse files
committed
chore: molecule stateflow using compose
1 parent dc2e09f commit defbde1

File tree

11 files changed

+276
-216
lines changed

11 files changed

+276
-216
lines changed

common/src/commonMain/kotlin/dev/suresh/flow/Counter.kt

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package dev.suresh.flow
2+
3+
import androidx.compose.runtime.*
4+
import app.cash.molecule.RecompositionMode
5+
import app.cash.molecule.moleculeFlow
6+
import kotlinx.coroutines.delay
7+
import kotlinx.datetime.*
8+
9+
@Composable
10+
fun timer(tz: TimeZone): LocalDateTime {
11+
var time by remember { mutableStateOf(currentTime(tz)) }
12+
LaunchedEffect(Unit) {
13+
while (true) {
14+
delay(1000)
15+
time = currentTime(tz)
16+
}
17+
}
18+
return time
19+
}
20+
21+
private fun currentTime(tz: TimeZone) = Clock.System.now().toLocalDateTime(tz)
22+
23+
fun timerComposeFlow(tz: TimeZone = TimeZone.currentSystemDefault()) =
24+
moleculeFlow(RecompositionMode.Immediate) { timer(tz) }

compose/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## [JetBrains Compose Multiplatform][1] Projects
2+
3+
4+
### Resources
5+
6+
* [Jetbrains Compose Compiler - Kotlin Compatibility](https://github.com/JetBrains/compose-multiplatform/blob/master/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeCompilerCompatibility.kt#L7)
7+
* [Jetpack Compose Compiler - Kotlin Compatibility](https://developer.android.com/jetpack/androidx/releases/compose-kotlin#pre-release_kotlin_compatibility)
8+
* [JetBrains Compose Multiplatform Versioning](https://github.com/JetBrains/compose-multiplatform/blob/master/VERSIONING.md)
9+
* [Jetbrains Compose Multiplatform Core Repo](https://github.com/JetBrains/compose-multiplatform-core)
10+
11+
12+
[1]: https://github.com/JetBrains/compose-multiplatform

dep-mgmt/bom/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
`java-platform`
3-
id("plugins.publishing")
3+
plugins.publishing
44
}
55

66
description = "A platform (BOM) used to align all module versions"

dep-mgmt/catalog/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
2-
id("plugins.catalog")
3-
id("plugins.publishing")
2+
plugins.catalog
3+
plugins.publishing
44
}
55

66
description = "Publish gradle version catalog!"

gradle/build-logic/common-plugins/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ dependencies {
121121
implementation(libs.build.foojay.resolver)
122122
implementation(libs.build.nativeimage.plugin)
123123
implementation(libs.build.modulegraph.plugin)
124+
implementation(libs.build.cash.molecule.plugin)
124125
testImplementation(gradleTestKit())
125-
// implementation(libs.build.cash.molecule.plugin)
126126
// implementation(libs.build.mokkery.plugin)
127127
// implementation(libs.build.jte.plugin)
128128
// implementation(libs.build.includegit.plugin)

gradle/build-logic/common-plugins/src/main/kotlin/common/KotlinExtns.kt

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import org.gradle.api.artifacts.ExternalDependency
66
import org.gradle.api.attributes.Attribute
77
import org.gradle.api.provider.Provider
88
import org.gradle.api.tasks.compile.JavaCompile
9-
import org.gradle.api.tasks.testing.Test
9+
import org.gradle.api.tasks.testing.*
1010
import org.gradle.api.tasks.testing.logging.*
1111
import org.gradle.jvm.toolchain.*
12+
import org.gradle.kotlin.dsl.KotlinClosure2
1213
import org.gradle.kotlin.dsl.assign
1314
import org.gradle.plugin.use.PluginDependency
1415
import org.jetbrains.kotlin.gradle.dsl.*
@@ -199,19 +200,52 @@ fun Test.configureJavaTest() {
199200
useJUnitPlatform()
200201
jvmArgs(jvmArguments)
201202
reports.html.required = true
202-
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1
203+
203204
testLogging {
204-
events =
205-
setOf(
206-
TestLogEvent.STANDARD_ERROR,
207-
TestLogEvent.FAILED,
208-
TestLogEvent.SKIPPED,
205+
configureLogEvents()
206+
}
207+
208+
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1
209+
210+
afterSuite(KotlinClosure2({ desc: TestDescriptor, result: TestResult ->
211+
if (desc.parent == null) { // will match the outermost suite
212+
println("""
213+
|Test Results
214+
|------------
215+
| Tests : ${result.resultType} (${result.testCount}
216+
| Successes : ${result.successfulTestCount}
217+
| Failures : ${result.failedTestCount}
218+
| Skipped : ${result.skippedTestCount}
219+
| """.trimMargin()
209220
)
221+
}
222+
}))
223+
}
224+
225+
fun TestLoggingContainer.configureLogEvents() {
226+
events = setOf(
227+
TestLogEvent.FAILED,
228+
TestLogEvent.PASSED,
229+
TestLogEvent.SKIPPED,
230+
TestLogEvent.STANDARD_OUT,
231+
)
232+
exceptionFormat = TestExceptionFormat.FULL
233+
showExceptions = true
234+
showCauses = true
235+
showStackTraces = true
236+
showStandardStreams = true
237+
238+
// set options for log level DEBUG and INFO
239+
debug {
240+
events = setOf(
241+
TestLogEvent.STARTED,
242+
TestLogEvent.FAILED,
243+
TestLogEvent.PASSED,
244+
TestLogEvent.SKIPPED,
245+
TestLogEvent.STANDARD_ERROR,
246+
TestLogEvent.STANDARD_OUT
247+
)
210248
exceptionFormat = TestExceptionFormat.FULL
211-
showExceptions = true
212-
showCauses = true
213-
showStackTraces = true
214-
showStandardStreams = true
215249
}
216250
}
217251

gradle/build-logic/common-plugins/src/main/kotlin/plugins/kotlin.mpp.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ plugins {
2020
id("dev.zacsweers.redacted")
2121
id("org.jetbrains.dokka")
2222
id("org.jetbrains.kotlinx.kover")
23-
// id("app.cash.molecule")
23+
id("app.cash.molecule")
2424
// id("dev.mokkery")
2525
}
2626

@@ -80,7 +80,7 @@ kotlinMultiplatform.apply {
8080
testTask(
8181
Action {
8282
enabled = true
83-
testLogging.showStandardStreams = true
83+
testLogging { configureLogEvents() }
8484
useKarma { useChromeHeadless() }
8585
})
8686

0 commit comments

Comments
 (0)