Skip to content

Commit 1332b66

Browse files
committed
finished refactor #2
1 parent 922ae2d commit 1332b66

File tree

13 files changed

+103
-65
lines changed

13 files changed

+103
-65
lines changed

core/build.gradle.kts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ kotlin {
4545

4646
implementation(compose.runtime)
4747
implementation(libs.common.lifecycle.viewmodelCompose)
48-
49-
50-
//implementation(project.dependencies.platform(libs.androidx.compose.bom))
51-
//implementation(libs.androidx.lifecycle.viewmodel.ktx)
52-
//implementation(libs.androidx.compose.ui)
53-
//implementation(libs.androidx.lifecycle.viewmodel.ktx)
54-
//implementation(libs.androidx.lifecycle.viewmodel.compose)
5548
}
5649
commonTest.dependencies {
5750
implementation(libs.kotlin.test)

core/src/commonMain/kotlin/com/bridge/ouroboros/compose/ExecutableEffect.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ abstract class ExecutableEffect<EVENT, EFFECT_STATE> : CoroutineScope {
2929
}
3030

3131
companion object {
32-
@Volatile
3332
private var defaultDispatcher: CoroutineDispatcher = Dispatchers.Default
3433

3534
fun setDefaultDispatcher(dispatcher: CoroutineDispatcher) {

core/src/commonMain/kotlin/com/bridge/ouroboros/compose/LoopState.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import androidx.compose.runtime.setValue
88
import androidx.lifecycle.ViewModel
99
import androidx.lifecycle.ViewModelProvider
1010
import androidx.lifecycle.viewModelScope
11+
import androidx.lifecycle.viewmodel.CreationExtras
1112
import androidx.lifecycle.viewmodel.compose.viewModel
1213
import kotlinx.coroutines.CoroutineExceptionHandler
1314
import kotlinx.coroutines.CoroutineScope
1415
import kotlinx.coroutines.flow.Flow
1516
import kotlinx.coroutines.launch
1617
import kotlinx.coroutines.plus
1718
import kotlin.coroutines.cancellation.CancellationException
19+
import kotlin.reflect.KClass
1820

1921
class LoopState<MODEL : Any, EVENT : ActionableEvent<MODEL, EFFECT>, EFFECT : ExecutableEffect<EVENT, EFFECT_STATE>, EFFECT_STATE>(
2022
initialModel: MODEL,
@@ -76,10 +78,7 @@ class LoopState<MODEL : Any, EVENT : ActionableEvent<MODEL, EFFECT>, EFFECT : Ex
7678
}
7779

7880
companion object {
79-
80-
@Volatile
8181
var loopScopeCustomizer: CoroutineScopeCustomizer = { it }
82-
8382
}
8483
}
8584

@@ -113,7 +112,7 @@ class LoopStateViewModel<MODEL : Any, EVENT : ActionableEvent<MODEL, EFFECT>, EF
113112

114113
@Composable
115114
inline fun <reified MODEL : Any, EVENT : ActionableEvent<MODEL, EFFECT>, EFFECT : ExecutableEffect<EVENT, EFFECT_STATE>, EFFECT_STATE> acquireLoop(
116-
key: String? = MODEL::class.java.name,
115+
key: String? = MODEL::class.qualifiedName,
117116
crossinline loopInitializer: LoopInitializer<MODEL, EFFECT>,
118117
crossinline effectStateFactory: EffectStateFactory<EFFECT_STATE>,
119118
noinline crashHandler: CrashHandler = {
@@ -127,7 +126,10 @@ inline fun <reified MODEL : Any, EVENT : ActionableEvent<MODEL, EFFECT>, EFFECT
127126
key = key,
128127
factory = remember {
129128
object : ViewModelProvider.Factory {
130-
override fun <T : ViewModel> create(modelClass: Class<T>): T {
129+
override fun <T : ViewModel> create(
130+
modelClass: KClass<T>,
131+
extras: CreationExtras
132+
): T {
131133
val (model, effects) = loopInitializer()
132134
val effectState = effectStateFactory()
133135

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
agp = "8.6.0-alpha08"
2+
agp = "8.6.1"
33
android-compileSdk = "34"
44
android-minSdk = "24"
55
android-targetSdk = "34"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#Wed Jul 31 08:39:04 CEST 2024
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
55
networkTimeout=10000
66
zipStoreBase=GRADLE_USER_HOME
77
zipStorePath=wrapper/dists

test/build.gradle

Lines changed: 0 additions & 26 deletions
This file was deleted.

test/build.gradle.kts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (C) 2019 - present Instructure, Inc.
3+
*/
4+
5+
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
6+
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
7+
8+
plugins {
9+
alias(libs.plugins.android.library)
10+
alias(libs.plugins.compose.compiler)
11+
alias(libs.plugins.compose.multiplatform)
12+
alias(libs.plugins.kotlin.multiplatform)
13+
}
14+
15+
kotlin {
16+
androidTarget {
17+
compilations.all {
18+
kotlinOptions {
19+
jvmTarget = "17"
20+
}
21+
}
22+
}
23+
24+
@OptIn(ExperimentalWasmDsl::class)
25+
wasmJs {
26+
browser {
27+
val projectDirPath = project.projectDir.path
28+
commonWebpackConfig {
29+
outputFileName = "ouroboroscompose.js"
30+
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
31+
static = (static ?: mutableListOf()).apply {
32+
// Serve sources to debug inside browser
33+
add(projectDirPath)
34+
}
35+
}
36+
}
37+
}
38+
binaries.executable()
39+
}
40+
41+
sourceSets {
42+
commonMain.dependencies {
43+
api(project(":core"))
44+
implementation(libs.coroutines.core)
45+
implementation(libs.coroutines.trest)
46+
implementation(libs.junit)
47+
implementation(libs.kotlin.test)
48+
}
49+
commonTest.dependencies {
50+
}
51+
}
52+
}
53+
54+
android {
55+
namespace = "com.bridge.ouroboros.compose.test"
56+
compileSdk = 35
57+
58+
defaultConfig {
59+
minSdk = 21
60+
targetSdk = 35
61+
}
62+
63+
compileOptions {
64+
sourceCompatibility = JavaVersion.VERSION_17
65+
targetCompatibility = JavaVersion.VERSION_17
66+
}
67+
68+
buildFeatures {
69+
compose = true
70+
}
71+
}

test/src/main/kotlin/com/bridge/ouroboros/compose/test/EffectMatching.kt renamed to test/src/commonMain/kotlin/com/bridge/ouroboros/compose/test/EffectMatching.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.bridge.ouroboros.compose.test
22

3-
import kotlin.test.junit.JUnitAsserter.assertEquals
4-
import kotlin.test.junit.JUnitAsserter.assertTrue
3+
import kotlin.test.assertEquals
4+
import kotlin.test.assertTrue
5+
56

67
class EffectMatching<E>(
78
capturedEvents: Set<E>,
@@ -15,11 +16,11 @@ class EffectMatching<E>(
1516
}
1617

1718
fun expectEvents(vararg events: E) {
18-
assertEquals("Expected events to be $events", events.toSet(), emittedEvents.toSet())
19+
assertEquals(events.toSet(), emittedEvents.toSet(),"Expected events to be $events")
1920
}
2021

2122
fun expectNoEvents() {
22-
assertTrue("Expected events to be empty", emittedEvents.isEmpty())
23+
assertTrue(emittedEvents.isEmpty(), "Expected events to be empty")
2324
}
2425

2526
operator fun invoke(block: EffectMatching<E>.() -> Unit) {

test/src/main/kotlin/com/bridge/ouroboros/compose/test/NextMatching.kt renamed to test/src/commonMain/kotlin/com/bridge/ouroboros/compose/test/NextMatching.kt

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.bridge.ouroboros.compose.test
22

33
import com.bridge.ouroboros.compose.Next
4-
import kotlin.test.junit.JUnitAsserter.assertEquals
5-
import kotlin.test.junit.JUnitAsserter.assertNull
6-
import kotlin.test.junit.JUnitAsserter.assertTrue
4+
import kotlin.test.assertEquals
5+
import kotlin.test.assertNull
6+
import kotlin.test.assertTrue
7+
78

89
class NextMatching<M, F>(private val next: Next<M, F>) {
910

@@ -23,33 +24,38 @@ class NextMatching<M, F>(private val next: Next<M, F>) {
2324
return next.effects
2425
}
2526

26-
val mustHaveModel: M get() {
27-
modelAccessed = true
28-
return checkNotNull(next.modelOrNull()) { "Expected model but there was none" }
29-
}
27+
val mustHaveModel: M
28+
get() {
29+
modelAccessed = true
30+
return checkNotNull(next.modelOrNull()) { "Expected model but there was none" }
31+
}
3032

3133
fun shouldHaveModel(model: M) {
32-
assertEquals("Expect new model to be $model", model, newModel)
34+
assertEquals(expected = model, actual = newModel, message = "Expect new model to be $model")
3335
}
3436

3537
fun shouldNotHaveModel() {
36-
assertNull("Expected no new model", newModel)
38+
assertNull(newModel, "Expected no new model")
3739
}
3840

3941
fun shouldHaveEffects(vararg effects: F) {
4042
newEffects shouldEmit effects.toSet()
4143
}
4244

4345
infix fun Set<F>.shouldEmit(effects: Set<F>) {
44-
assertEquals("Expecting effects to be $effects", effects, newEffects)
46+
assertEquals(
47+
expected = effects,
48+
actual = newEffects,
49+
message = "Expecting effects to be $effects"
50+
)
4551
}
4652

4753
infix fun Set<F>.shouldEmit(effect: F) {
4854
shouldEmit(setOf(effect))
4955
}
5056

5157
fun shouldNotHaveEffects() {
52-
assertTrue("No effects should be emitted", newEffects.isEmpty())
58+
assertTrue(newEffects.isEmpty(), "No effects should be emitted")
5359
}
5460

5561
fun shouldNotChange() {

0 commit comments

Comments
 (0)