diff --git a/mvi-declarative/build.gradle.kts b/mvi-declarative/build.gradle.kts deleted file mode 100644 index 2e49a92..0000000 --- a/mvi-declarative/build.gradle.kts +++ /dev/null @@ -1,47 +0,0 @@ -import org.jlleitschuh.gradle.ktlint.KtlintExtension - -plugins { - kotlin("jvm") version libs.versions.kotlin.get() - alias(libs.plugins.ktlint) - alias(libs.plugins.mavenPublish) -} - -kotlin { - explicitApi() -} - -val compileTestKotlin: org.jetbrains.kotlin.gradle.tasks.KotlinCompile by tasks -compileTestKotlin.kotlinOptions { - freeCompilerArgs += "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi" -} - -repositories { - mavenCentral() - maven("https://jitpack.io") -} - -configure { - version.set(libs.versions.ktlint.get()) -} - -tasks.getByName("test") { - useJUnitPlatform() -} - -lateinit var sourcesArtifact: PublishArtifact -tasks { - val sourcesJar by creating(Jar::class) { - archiveClassifier.set("sources") - from(sourceSets["main"].allJava.srcDirs) - } - - artifacts { - sourcesArtifact = archives(sourcesJar) - } -} - -dependencies { - api(project(":mvi")) - implementation(libs.coroutines.core) - testImplementation(libs.kotest.runner) -} diff --git a/mvi-declarative/gradle.properties b/mvi-declarative/gradle.properties deleted file mode 100644 index bedb8b7..0000000 --- a/mvi-declarative/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -POM_ARTIFACT_ID=mvi-declarative diff --git a/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/MviState.kt b/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/MviState.kt deleted file mode 100644 index 110d0d4..0000000 --- a/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/MviState.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.adidas.mvi.declarative - -import com.adidas.mvi.State -import com.adidas.mvi.sideeffects.SideEffects - -public data class MviState(val state: TState, val sideEffects: SideEffects) : State diff --git a/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/transform/StateTransform.kt b/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/transform/StateTransform.kt deleted file mode 100644 index acbcc0f..0000000 --- a/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/transform/StateTransform.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.adidas.mvi.declarative.transform - -import com.adidas.mvi.declarative.MviState -import com.adidas.mvi.transform.StateTransform - -public abstract class StateTransform : - StateTransform> { - - protected abstract fun mutate(currentState: TState): TState - - final override fun reduce(currentState: MviState): MviState { - return currentState.copy(state = mutate(currentState.state)) - } -} diff --git a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/SideEffectTransformTest.kt b/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/SideEffectTransformTest.kt deleted file mode 100644 index 1876da0..0000000 --- a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/SideEffectTransformTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.adidas.mvi.declarative.transform - -import com.adidas.mvi.declarative.MviState -import com.adidas.mvi.declarative.transform.product.FakeProductSideEffectTransform -import com.adidas.mvi.declarative.transform.product.ProductSideEffect -import com.adidas.mvi.declarative.transform.product.ProductState -import com.adidas.mvi.sideeffects.SideEffects -import io.kotest.core.spec.style.ShouldSpec -import io.kotest.matchers.collections.shouldContainExactly - -class SideEffectTransformTest : ShouldSpec({ - - context("SideEffectTransform") { - val sideEffect = ProductSideEffect.NavigateToProductDetailsSideEffect - - should("use mutate() function for reducing SideEffects") { - val mviState = MviState(ProductState.Loading, SideEffects()) - FakeProductSideEffectTransform(sideEffect).reduce(mviState).sideEffects shouldContainExactly - listOf(sideEffect) - } - } -}) diff --git a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/StateTransformTest.kt b/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/StateTransformTest.kt deleted file mode 100644 index 8ebbe49..0000000 --- a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/StateTransformTest.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.adidas.mvi.declarative.transform - -import com.adidas.mvi.declarative.MviState -import com.adidas.mvi.declarative.transform.product.FakeProductStateTransform -import com.adidas.mvi.declarative.transform.product.ProductSideEffect -import com.adidas.mvi.declarative.transform.product.ProductState -import com.adidas.mvi.sideeffects.SideEffects -import io.kotest.core.spec.style.ShouldSpec -import io.kotest.matchers.shouldBe - -class StateTransformTest : ShouldSpec({ - - context("StateTransform implementation") { - val state = ProductState.Loaded - - should("use mutate() function for reducing state") { - val mviState = MviState(ProductState.Loading, SideEffects()) - FakeProductStateTransform(state).reduce(mviState).state shouldBe state - } - } -}) diff --git a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/FakeProductStateTransform.kt b/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/FakeProductStateTransform.kt deleted file mode 100644 index 5319abb..0000000 --- a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/FakeProductStateTransform.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.adidas.mvi.declarative.transform.product - -import com.adidas.mvi.declarative.transform.StateTransform - -class FakeProductStateTransform(private val state: ProductState) : StateTransform() { - - override fun mutate(currentState: ProductState): ProductState { - return state - } -} diff --git a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/ProductState.kt b/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/ProductState.kt deleted file mode 100644 index 9611b44..0000000 --- a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/ProductState.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.adidas.mvi.declarative.transform.product - -import com.adidas.mvi.State - -sealed class ProductState : State { - object Loading : ProductState() - object Loaded : ProductState() -} diff --git a/mvi/src/main/kotlin/com/adidas/mvi/IntentExecutor.kt b/mvi/src/main/kotlin/com/adidas/mvi/IntentExecutor.kt index ccb2d0c..6c449c1 100644 --- a/mvi/src/main/kotlin/com/adidas/mvi/IntentExecutor.kt +++ b/mvi/src/main/kotlin/com/adidas/mvi/IntentExecutor.kt @@ -3,6 +3,6 @@ package com.adidas.mvi import com.adidas.mvi.transform.StateTransform import kotlinx.coroutines.flow.Flow -public fun interface IntentExecutor { +public fun interface IntentExecutor { public fun executeIntent(intent: TIntent, jobTerminator: JobTerminator): Flow> } diff --git a/mvi/src/main/kotlin/com/adidas/mvi/LoggableState.kt b/mvi/src/main/kotlin/com/adidas/mvi/LoggableState.kt new file mode 100644 index 0000000..646243a --- /dev/null +++ b/mvi/src/main/kotlin/com/adidas/mvi/LoggableState.kt @@ -0,0 +1,3 @@ +package com.adidas.mvi + +public interface LoggableState : Loggable diff --git a/mvi/src/main/kotlin/com/adidas/mvi/Reducer.kt b/mvi/src/main/kotlin/com/adidas/mvi/Reducer.kt index c1ac88d..b3e7a8f 100644 --- a/mvi/src/main/kotlin/com/adidas/mvi/Reducer.kt +++ b/mvi/src/main/kotlin/com/adidas/mvi/Reducer.kt @@ -26,7 +26,7 @@ public class Reducer @Deprecated("Use the other constructor, th private val defaultDispatcher: CoroutineDispatcher = Dispatchers.Default, private val intentExecutor: IntentExecutor ) where TIntent : Intent, - TState : State { + TState : LoggableState { @Suppress("DEPRECATION") public constructor( coroutineScope: CoroutineScope, diff --git a/mvi/src/main/kotlin/com/adidas/mvi/State.kt b/mvi/src/main/kotlin/com/adidas/mvi/State.kt index f7537e2..6fc583e 100644 --- a/mvi/src/main/kotlin/com/adidas/mvi/State.kt +++ b/mvi/src/main/kotlin/com/adidas/mvi/State.kt @@ -1,3 +1,5 @@ package com.adidas.mvi -public interface State : Loggable +import com.adidas.mvi.sideeffects.SideEffects + +public data class State(val view: TState, val sideEffects: SideEffects) : LoggableState diff --git a/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/ReducerExtensions.kt b/mvi/src/main/kotlin/com/adidas/mvi/reducer/ReducerExtensions.kt similarity index 62% rename from mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/ReducerExtensions.kt rename to mvi/src/main/kotlin/com/adidas/mvi/reducer/ReducerExtensions.kt index 1e4b3a5..b2e48a1 100644 --- a/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/ReducerExtensions.kt +++ b/mvi/src/main/kotlin/com/adidas/mvi/reducer/ReducerExtensions.kt @@ -1,25 +1,26 @@ -package com.adidas.mvi.declarative +package com.adidas.mvi.reducer import com.adidas.mvi.Intent +import com.adidas.mvi.LoggableState import com.adidas.mvi.Logger import com.adidas.mvi.Reducer import com.adidas.mvi.SimplifiedIntentExecutor import com.adidas.mvi.State -import com.adidas.mvi.actions.Actions +import com.adidas.mvi.sideeffects.SideEffects import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -public fun Reducer( +public fun Reducer( coroutineScope: CoroutineScope, initialInnerState: TInnerState, - intentExecutor: SimplifiedIntentExecutor>, + intentExecutor: SimplifiedIntentExecutor>, logger: Logger? = null, defaultDispatcher: CoroutineDispatcher = Dispatchers.Default -): Reducer> { +): Reducer> { return Reducer( coroutineScope = coroutineScope, - initialState = MviState(initialInnerState, Actions()), + initialState = State(initialInnerState, SideEffects()), intentExecutor = intentExecutor, logger = logger, defaultDispatcher = defaultDispatcher diff --git a/mvi/src/main/kotlin/com/adidas/mvi/requirements/ReduceExtensions.kt b/mvi/src/main/kotlin/com/adidas/mvi/requirements/ReduceExtensions.kt index 9e7ba01..51b3f0b 100644 --- a/mvi/src/main/kotlin/com/adidas/mvi/requirements/ReduceExtensions.kt +++ b/mvi/src/main/kotlin/com/adidas/mvi/requirements/ReduceExtensions.kt @@ -1,20 +1,20 @@ package com.adidas.mvi.requirements -import com.adidas.mvi.State +import com.adidas.mvi.LoggableState -public inline fun requireAndReduceState( +public inline fun requireAndReduceState( state: TState, noinline reduce: (TRequiredState) -> TState ): TState { return StateReduceRequirement(TRequiredState::class, reduce).reduce(state) } -public inline fun requireState( +public inline fun requireState( noinline reduce: (TRequiredState) -> TState ): ReduceRequirement { return StateReduceRequirement(TRequiredState::class, reduce) } -public infix fun ReduceRequirement.or(another: ReduceRequirement): ReduceRequirement { +public infix fun ReduceRequirement.or(another: ReduceRequirement): ReduceRequirement { return DoubleReduceRequirement(this, another) } diff --git a/mvi/src/main/kotlin/com/adidas/mvi/requirements/StateReduceRequirement.kt b/mvi/src/main/kotlin/com/adidas/mvi/requirements/StateReduceRequirement.kt index cf47100..b6a9e91 100644 --- a/mvi/src/main/kotlin/com/adidas/mvi/requirements/StateReduceRequirement.kt +++ b/mvi/src/main/kotlin/com/adidas/mvi/requirements/StateReduceRequirement.kt @@ -1,6 +1,6 @@ package com.adidas.mvi.requirements -import com.adidas.mvi.State +import com.adidas.mvi.LoggableState import com.adidas.mvi.StateRequiredNotFulfilledException import kotlin.reflect.KClass import kotlin.reflect.cast @@ -8,7 +8,7 @@ import kotlin.reflect.cast public class StateReduceRequirement( private val expectedState: KClass, private val reduceFunction: (TRequiredState) -> TState -) : ReduceRequirement where TState : State, TRequiredState : TState { +) : ReduceRequirement where TState : LoggableState, TRequiredState : TState { public override fun reduce(state: TState): TState { if (expectedState.isInstance(state)) { diff --git a/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/transform/SideEffectTransform.kt b/mvi/src/main/kotlin/com/adidas/mvi/transform/SideEffectTransform.kt similarity index 53% rename from mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/transform/SideEffectTransform.kt rename to mvi/src/main/kotlin/com/adidas/mvi/transform/SideEffectTransform.kt index 41fc7f1..94d34fe 100644 --- a/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/transform/SideEffectTransform.kt +++ b/mvi/src/main/kotlin/com/adidas/mvi/transform/SideEffectTransform.kt @@ -1,15 +1,14 @@ -package com.adidas.mvi.declarative.transform +package com.adidas.mvi.transform -import com.adidas.mvi.declarative.MviState +import com.adidas.mvi.State import com.adidas.mvi.sideeffects.SideEffects -import com.adidas.mvi.transform.StateTransform public abstract class SideEffectTransform : - StateTransform> { + StateTransform> { protected abstract fun mutate(sideEffects: SideEffects): SideEffects - final override fun reduce(currentState: MviState): MviState { + final override fun reduce(currentState: State): State { val sideEffects = currentState.sideEffects return currentState.copy(sideEffects = mutate(sideEffects)) } diff --git a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/FakeProductSideEffectTransform.kt b/mvi/src/test/kotlin/com/adidas/mvi/product/FakeProductSideEffectTransform.kt similarity index 74% rename from mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/FakeProductSideEffectTransform.kt rename to mvi/src/test/kotlin/com/adidas/mvi/product/FakeProductSideEffectTransform.kt index 2383a90..cd096ef 100644 --- a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/FakeProductSideEffectTransform.kt +++ b/mvi/src/test/kotlin/com/adidas/mvi/product/FakeProductSideEffectTransform.kt @@ -1,7 +1,7 @@ -package com.adidas.mvi.declarative.transform.product +package com.adidas.mvi.product -import com.adidas.mvi.declarative.transform.SideEffectTransform import com.adidas.mvi.sideeffects.SideEffects +import com.adidas.mvi.transform.SideEffectTransform class FakeProductSideEffectTransform(private val sideEffect: ProductSideEffect) : SideEffectTransform() { diff --git a/mvi/src/test/kotlin/com/adidas/mvi/product/FakeProductStateTransform.kt b/mvi/src/test/kotlin/com/adidas/mvi/product/FakeProductStateTransform.kt new file mode 100644 index 0000000..2bf58f3 --- /dev/null +++ b/mvi/src/test/kotlin/com/adidas/mvi/product/FakeProductStateTransform.kt @@ -0,0 +1,12 @@ +package com.adidas.mvi.product + +import com.adidas.mvi.State +import com.adidas.mvi.transform.StateTransform + +class FakeProductStateTransform(private val state: State) : + StateTransform { + + override fun reduce(currentState: ProductState): ProductState { + return state.view + } +} diff --git a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/ProductSideEffect.kt b/mvi/src/test/kotlin/com/adidas/mvi/product/ProductSideEffect.kt similarity index 66% rename from mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/ProductSideEffect.kt rename to mvi/src/test/kotlin/com/adidas/mvi/product/ProductSideEffect.kt index 39dc65a..255f7a6 100644 --- a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/ProductSideEffect.kt +++ b/mvi/src/test/kotlin/com/adidas/mvi/product/ProductSideEffect.kt @@ -1,4 +1,4 @@ -package com.adidas.mvi.declarative.transform.product +package com.adidas.mvi.product sealed class ProductSideEffect { object NavigateToProductDetailsSideEffect : ProductSideEffect() diff --git a/mvi/src/test/kotlin/com/adidas/mvi/product/ProductState.kt b/mvi/src/test/kotlin/com/adidas/mvi/product/ProductState.kt new file mode 100644 index 0000000..e49b071 --- /dev/null +++ b/mvi/src/test/kotlin/com/adidas/mvi/product/ProductState.kt @@ -0,0 +1,8 @@ +package com.adidas.mvi.product + +import com.adidas.mvi.LoggableState + +sealed class ProductState : LoggableState { + object Loading : ProductState() + object Loaded : ProductState() +} diff --git a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/ReducerExtensionsTest.kt b/mvi/src/test/kotlin/com/adidas/mvi/reducer/ReducerExtensionsTest.kt similarity index 60% rename from mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/ReducerExtensionsTest.kt rename to mvi/src/test/kotlin/com/adidas/mvi/reducer/ReducerExtensionsTest.kt index abdb928..e75ae6f 100644 --- a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/ReducerExtensionsTest.kt +++ b/mvi/src/test/kotlin/com/adidas/mvi/reducer/ReducerExtensionsTest.kt @@ -1,10 +1,9 @@ -package com.adidas.mvi.declarative.transform +package com.adidas.mvi.reducer import com.adidas.mvi.Intent -import com.adidas.mvi.declarative.MviState -import com.adidas.mvi.declarative.Reducer -import com.adidas.mvi.declarative.transform.product.ProductState -import com.adidas.mvi.transform.Transform +import com.adidas.mvi.State +import com.adidas.mvi.product.ProductState +import com.adidas.mvi.transform.StateTransform import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe import kotlinx.coroutines.flow.emptyFlow @@ -16,12 +15,12 @@ class ReducerExtensionsTest : ShouldSpec({ coroutineScope = TestScope(), initialInnerState = ProductState.Loading, intentExecutor = { _: Intent -> - emptyFlow>>() + emptyFlow>>() } ) should("The initial inner state should be Loading") { - reducer.state.value.state shouldBe ProductState.Loading + reducer.state.value.view shouldBe ProductState.Loading } } }) diff --git a/mvi/src/test/kotlin/com/adidas/mvi/reducer/TestState.kt b/mvi/src/test/kotlin/com/adidas/mvi/reducer/TestState.kt index 46242e6..a083847 100644 --- a/mvi/src/test/kotlin/com/adidas/mvi/reducer/TestState.kt +++ b/mvi/src/test/kotlin/com/adidas/mvi/reducer/TestState.kt @@ -1,8 +1,8 @@ package com.adidas.mvi.reducer -import com.adidas.mvi.State +import com.adidas.mvi.LoggableState -internal sealed class TestState : State { +internal sealed class TestState : LoggableState { object InitialState : TestState() object StateFromTransform1 : TestState() diff --git a/mvi/src/test/kotlin/com/adidas/mvi/requirements/ReduceRequirementTests.kt b/mvi/src/test/kotlin/com/adidas/mvi/requirements/ReduceRequirementTests.kt index 87771db..c64ce74 100644 --- a/mvi/src/test/kotlin/com/adidas/mvi/requirements/ReduceRequirementTests.kt +++ b/mvi/src/test/kotlin/com/adidas/mvi/requirements/ReduceRequirementTests.kt @@ -1,6 +1,6 @@ package com.adidas.mvi.requirements -import com.adidas.mvi.State +import com.adidas.mvi.LoggableState import com.adidas.mvi.StateRequiredNotFulfilledException import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.IsolationMode @@ -8,7 +8,7 @@ import io.kotest.core.spec.style.BehaviorSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeInstanceOf -private sealed class TestState : State { +private sealed class TestState : LoggableState { object State1 : TestState() object State2 : TestState() object State3 : TestState() diff --git a/mvi/src/test/kotlin/com/adidas/mvi/transform/SideEffectTransformTest.kt b/mvi/src/test/kotlin/com/adidas/mvi/transform/SideEffectTransformTest.kt new file mode 100644 index 0000000..254bea9 --- /dev/null +++ b/mvi/src/test/kotlin/com/adidas/mvi/transform/SideEffectTransformTest.kt @@ -0,0 +1,22 @@ +package com.adidas.mvi.transform + +import com.adidas.mvi.State +import com.adidas.mvi.product.FakeProductSideEffectTransform +import com.adidas.mvi.product.ProductSideEffect +import com.adidas.mvi.product.ProductState +import com.adidas.mvi.sideeffects.SideEffects +import io.kotest.core.spec.style.ShouldSpec +import io.kotest.matchers.collections.shouldContainExactly + +class SideEffectTransformTest : ShouldSpec({ + + context("SideEffectTransform") { + val sideEffect = ProductSideEffect.NavigateToProductDetailsSideEffect + + should("use mutate() function for reducing SideEffects") { + val state = State(ProductState.Loading, SideEffects()) + FakeProductSideEffectTransform(sideEffect).reduce(state).sideEffects shouldContainExactly + listOf(sideEffect) + } + } +}) diff --git a/mvi/src/test/kotlin/com/adidas/mvi/transform/StateTransformTest.kt b/mvi/src/test/kotlin/com/adidas/mvi/transform/StateTransformTest.kt new file mode 100644 index 0000000..52797ea --- /dev/null +++ b/mvi/src/test/kotlin/com/adidas/mvi/transform/StateTransformTest.kt @@ -0,0 +1,21 @@ +package com.adidas.mvi.transform + +import com.adidas.mvi.State +import com.adidas.mvi.product.FakeProductStateTransform +import com.adidas.mvi.product.ProductSideEffect +import com.adidas.mvi.product.ProductState +import com.adidas.mvi.sideeffects.SideEffects +import io.kotest.core.spec.style.ShouldSpec +import io.kotest.matchers.shouldBe + +class StateTransformTest : ShouldSpec({ + + context("StateTransform implementation") { + val state = ProductState.Loaded + + should("use mutate() function for reducing state") { + val state = State(ProductState.Loading, SideEffects()) + FakeProductStateTransform(state).reduce(state.view) shouldBe state.view + } + } +}) diff --git a/settings.gradle.kts b/settings.gradle.kts index de0a6a9..823fff2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,2 @@ rootProject.name = "mvi" include(":mvi") -include(":mvi-declarative")