From 007e8f31eba68ff7f93ddb493b372d2996a108d8 Mon Sep 17 00:00:00 2001 From: Shervin Date: Wed, 3 Aug 2022 10:18:25 +0200 Subject: [PATCH 1/3] Rename State to LoggableState [Preparing to add State.kt] --- .../main/kotlin/com/adidas/mvi/declarative/MviState.kt | 4 ++-- .../com/adidas/mvi/declarative/ReducerExtensions.kt | 8 ++++---- .../mvi/declarative/transform/ReducerExtensionsTest.kt | 4 ++-- .../mvi/declarative/transform/product/ProductState.kt | 4 ++-- mvi/src/main/kotlin/com/adidas/mvi/IntentExecutor.kt | 2 +- mvi/src/main/kotlin/com/adidas/mvi/LoggableState.kt | 3 +++ mvi/src/main/kotlin/com/adidas/mvi/Reducer.kt | 2 +- mvi/src/main/kotlin/com/adidas/mvi/State.kt | 3 --- .../com/adidas/mvi/requirements/ReduceExtensions.kt | 8 ++++---- .../com/adidas/mvi/requirements/StateReduceRequirement.kt | 4 ++-- mvi/src/test/kotlin/com/adidas/mvi/reducer/TestState.kt | 4 ++-- .../com/adidas/mvi/requirements/ReduceRequirementTests.kt | 4 ++-- 12 files changed, 25 insertions(+), 25 deletions(-) create mode 100644 mvi/src/main/kotlin/com/adidas/mvi/LoggableState.kt delete mode 100644 mvi/src/main/kotlin/com/adidas/mvi/State.kt 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 index 110d0d4..20a05d3 100644 --- a/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/MviState.kt +++ b/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/MviState.kt @@ -1,6 +1,6 @@ package com.adidas.mvi.declarative -import com.adidas.mvi.State +import com.adidas.mvi.LoggableState import com.adidas.mvi.sideeffects.SideEffects -public data class MviState(val state: TState, val sideEffects: SideEffects) : State +public data class MviState(val state: TState, val sideEffects: SideEffects) : LoggableState diff --git a/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/ReducerExtensions.kt b/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/ReducerExtensions.kt index 1e4b3a5..2384569 100644 --- a/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/ReducerExtensions.kt +++ b/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/ReducerExtensions.kt @@ -1,16 +1,16 @@ package com.adidas.mvi.declarative 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>, @@ -19,7 +19,7 @@ public fun Reducer( ): Reducer> { return Reducer( coroutineScope = coroutineScope, - initialState = MviState(initialInnerState, Actions()), + initialState = MviState(initialInnerState, SideEffects()), intentExecutor = intentExecutor, logger = logger, defaultDispatcher = defaultDispatcher diff --git a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/ReducerExtensionsTest.kt b/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/ReducerExtensionsTest.kt index abdb928..317cd26 100644 --- a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/ReducerExtensionsTest.kt +++ b/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/ReducerExtensionsTest.kt @@ -4,7 +4,7 @@ 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.transform.StateTransform import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe import kotlinx.coroutines.flow.emptyFlow @@ -16,7 +16,7 @@ class ReducerExtensionsTest : ShouldSpec({ coroutineScope = TestScope(), initialInnerState = ProductState.Loading, intentExecutor = { _: Intent -> - emptyFlow>>() + emptyFlow>>() } ) 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 index 9611b44..9ac24ee 100644 --- 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 @@ -1,8 +1,8 @@ package com.adidas.mvi.declarative.transform.product -import com.adidas.mvi.State +import com.adidas.mvi.LoggableState -sealed class ProductState : State { +sealed class ProductState : LoggableState { 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 deleted file mode 100644 index f7537e2..0000000 --- a/mvi/src/main/kotlin/com/adidas/mvi/State.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.adidas.mvi - -public interface State : Loggable 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/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() From f7ca2391b3683db1295046d41dd13be89d3aaaab Mon Sep 17 00:00:00 2001 From: Shervin Date: Wed, 3 Aug 2022 16:45:55 +0200 Subject: [PATCH 2/3] Remove mvi-declarative --- mvi-declarative/build.gradle.kts | 47 ------------------- mvi-declarative/gradle.properties | 1 - .../declarative/transform/StateTransform.kt | 14 ------ .../product/FakeProductStateTransform.kt | 10 ---- .../main/kotlin/com/adidas/mvi}/MviState.kt | 3 +- .../adidas/mvi/reducer}/ReducerExtensions.kt | 3 +- .../mvi}/transform/SideEffectTransform.kt | 5 +- .../product/FakeProductSideEffectTransform.kt | 4 +- .../mvi/product/FakeProductStateTransform.kt | 10 ++++ .../adidas/mvi}/product/ProductSideEffect.kt | 2 +- .../com/adidas/mvi}/product/ProductState.kt | 2 +- .../mvi/reducer}/ReducerExtensionsTest.kt | 7 ++- .../mvi}/transform/SideEffectTransformTest.kt | 10 ++-- .../mvi}/transform/StateTransformTest.kt | 12 ++--- settings.gradle.kts | 1 - 15 files changed, 33 insertions(+), 98 deletions(-) delete mode 100644 mvi-declarative/build.gradle.kts delete mode 100644 mvi-declarative/gradle.properties delete mode 100644 mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/transform/StateTransform.kt delete mode 100644 mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/FakeProductStateTransform.kt rename {mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative => mvi/src/main/kotlin/com/adidas/mvi}/MviState.kt (71%) rename {mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative => mvi/src/main/kotlin/com/adidas/mvi/reducer}/ReducerExtensions.kt (94%) rename {mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative => mvi/src/main/kotlin/com/adidas/mvi}/transform/SideEffectTransform.kt (78%) rename {mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform => mvi/src/test/kotlin/com/adidas/mvi}/product/FakeProductSideEffectTransform.kt (74%) create mode 100644 mvi/src/test/kotlin/com/adidas/mvi/product/FakeProductStateTransform.kt rename {mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform => mvi/src/test/kotlin/com/adidas/mvi}/product/ProductSideEffect.kt (66%) rename {mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform => mvi/src/test/kotlin/com/adidas/mvi}/product/ProductState.kt (74%) rename {mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform => mvi/src/test/kotlin/com/adidas/mvi/reducer}/ReducerExtensionsTest.kt (79%) rename {mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative => mvi/src/test/kotlin/com/adidas/mvi}/transform/SideEffectTransformTest.kt (67%) rename {mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative => mvi/src/test/kotlin/com/adidas/mvi}/transform/StateTransformTest.kt (52%) 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/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/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/main/kotlin/com/adidas/mvi/declarative/MviState.kt b/mvi/src/main/kotlin/com/adidas/mvi/MviState.kt similarity index 71% rename from mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/MviState.kt rename to mvi/src/main/kotlin/com/adidas/mvi/MviState.kt index 20a05d3..355ece0 100644 --- a/mvi-declarative/src/main/kotlin/com/adidas/mvi/declarative/MviState.kt +++ b/mvi/src/main/kotlin/com/adidas/mvi/MviState.kt @@ -1,6 +1,5 @@ -package com.adidas.mvi.declarative +package com.adidas.mvi -import com.adidas.mvi.LoggableState import com.adidas.mvi.sideeffects.SideEffects public data class MviState(val state: 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 94% 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 2384569..14ba16d 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,8 +1,9 @@ -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.MviState import com.adidas.mvi.Reducer import com.adidas.mvi.SimplifiedIntentExecutor import com.adidas.mvi.sideeffects.SideEffects 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 78% 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..9b7a806 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,8 +1,7 @@ -package com.adidas.mvi.declarative.transform +package com.adidas.mvi.transform -import com.adidas.mvi.declarative.MviState +import com.adidas.mvi.MviState import com.adidas.mvi.sideeffects.SideEffects -import com.adidas.mvi.transform.StateTransform public abstract class SideEffectTransform : StateTransform> { 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..c25e1ad --- /dev/null +++ b/mvi/src/test/kotlin/com/adidas/mvi/product/FakeProductStateTransform.kt @@ -0,0 +1,10 @@ +package com.adidas.mvi.product + +import com.adidas.mvi.transform.StateTransform + +class FakeProductStateTransform(private val state: ProductState) : StateTransform { + + override fun reduce(currentState: ProductState): ProductState { + return state + } +} 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-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/ProductState.kt b/mvi/src/test/kotlin/com/adidas/mvi/product/ProductState.kt similarity index 74% rename from mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/ProductState.kt rename to mvi/src/test/kotlin/com/adidas/mvi/product/ProductState.kt index 9ac24ee..e49b071 100644 --- a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/product/ProductState.kt +++ b/mvi/src/test/kotlin/com/adidas/mvi/product/ProductState.kt @@ -1,4 +1,4 @@ -package com.adidas.mvi.declarative.transform.product +package com.adidas.mvi.product import com.adidas.mvi.LoggableState 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 79% 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 317cd26..a7fdea1 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,9 +1,8 @@ -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.MviState +import com.adidas.mvi.product.ProductState import com.adidas.mvi.transform.StateTransform import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe diff --git a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/SideEffectTransformTest.kt b/mvi/src/test/kotlin/com/adidas/mvi/transform/SideEffectTransformTest.kt similarity index 67% rename from mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/SideEffectTransformTest.kt rename to mvi/src/test/kotlin/com/adidas/mvi/transform/SideEffectTransformTest.kt index 1876da0..457cf92 100644 --- a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/SideEffectTransformTest.kt +++ b/mvi/src/test/kotlin/com/adidas/mvi/transform/SideEffectTransformTest.kt @@ -1,9 +1,9 @@ -package com.adidas.mvi.declarative.transform +package com.adidas.mvi.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.MviState +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 diff --git a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/StateTransformTest.kt b/mvi/src/test/kotlin/com/adidas/mvi/transform/StateTransformTest.kt similarity index 52% rename from mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/StateTransformTest.kt rename to mvi/src/test/kotlin/com/adidas/mvi/transform/StateTransformTest.kt index 8ebbe49..9a6318a 100644 --- a/mvi-declarative/src/test/kotlin/com/adidas/mvi/declarative/transform/StateTransformTest.kt +++ b/mvi/src/test/kotlin/com/adidas/mvi/transform/StateTransformTest.kt @@ -1,9 +1,9 @@ -package com.adidas.mvi.declarative.transform +package com.adidas.mvi.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.MviState +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 @@ -15,7 +15,7 @@ class StateTransformTest : ShouldSpec({ should("use mutate() function for reducing state") { val mviState = MviState(ProductState.Loading, SideEffects()) - FakeProductStateTransform(state).reduce(mviState).state shouldBe state + FakeProductStateTransform(state).reduce(mviState.state) shouldBe state } } }) 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") From 8ebe37c5e1dca4100152f598b38e18ed5b1d4358 Mon Sep 17 00:00:00 2001 From: Shervin Date: Thu, 4 Aug 2022 17:35:14 +0200 Subject: [PATCH 3/3] Rename MviState to State --- mvi/src/main/kotlin/com/adidas/mvi/MviState.kt | 5 ----- mvi/src/main/kotlin/com/adidas/mvi/State.kt | 5 +++++ .../kotlin/com/adidas/mvi/reducer/ReducerExtensions.kt | 8 ++++---- .../com/adidas/mvi/transform/SideEffectTransform.kt | 6 +++--- .../com/adidas/mvi/product/FakeProductStateTransform.kt | 6 ++++-- .../com/adidas/mvi/reducer/ReducerExtensionsTest.kt | 6 +++--- .../com/adidas/mvi/transform/SideEffectTransformTest.kt | 6 +++--- .../kotlin/com/adidas/mvi/transform/StateTransformTest.kt | 6 +++--- 8 files changed, 25 insertions(+), 23 deletions(-) delete mode 100644 mvi/src/main/kotlin/com/adidas/mvi/MviState.kt create mode 100644 mvi/src/main/kotlin/com/adidas/mvi/State.kt diff --git a/mvi/src/main/kotlin/com/adidas/mvi/MviState.kt b/mvi/src/main/kotlin/com/adidas/mvi/MviState.kt deleted file mode 100644 index 355ece0..0000000 --- a/mvi/src/main/kotlin/com/adidas/mvi/MviState.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.adidas.mvi - -import com.adidas.mvi.sideeffects.SideEffects - -public data class MviState(val state: TState, val sideEffects: SideEffects) : LoggableState diff --git a/mvi/src/main/kotlin/com/adidas/mvi/State.kt b/mvi/src/main/kotlin/com/adidas/mvi/State.kt new file mode 100644 index 0000000..6fc583e --- /dev/null +++ b/mvi/src/main/kotlin/com/adidas/mvi/State.kt @@ -0,0 +1,5 @@ +package com.adidas.mvi + +import com.adidas.mvi.sideeffects.SideEffects + +public data class State(val view: TState, val sideEffects: SideEffects) : LoggableState diff --git a/mvi/src/main/kotlin/com/adidas/mvi/reducer/ReducerExtensions.kt b/mvi/src/main/kotlin/com/adidas/mvi/reducer/ReducerExtensions.kt index 14ba16d..b2e48a1 100644 --- a/mvi/src/main/kotlin/com/adidas/mvi/reducer/ReducerExtensions.kt +++ b/mvi/src/main/kotlin/com/adidas/mvi/reducer/ReducerExtensions.kt @@ -3,9 +3,9 @@ package com.adidas.mvi.reducer import com.adidas.mvi.Intent import com.adidas.mvi.LoggableState import com.adidas.mvi.Logger -import com.adidas.mvi.MviState import com.adidas.mvi.Reducer import com.adidas.mvi.SimplifiedIntentExecutor +import com.adidas.mvi.State import com.adidas.mvi.sideeffects.SideEffects import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope @@ -14,13 +14,13 @@ import kotlinx.coroutines.Dispatchers 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, SideEffects()), + initialState = State(initialInnerState, SideEffects()), intentExecutor = intentExecutor, logger = logger, defaultDispatcher = defaultDispatcher diff --git a/mvi/src/main/kotlin/com/adidas/mvi/transform/SideEffectTransform.kt b/mvi/src/main/kotlin/com/adidas/mvi/transform/SideEffectTransform.kt index 9b7a806..94d34fe 100644 --- a/mvi/src/main/kotlin/com/adidas/mvi/transform/SideEffectTransform.kt +++ b/mvi/src/main/kotlin/com/adidas/mvi/transform/SideEffectTransform.kt @@ -1,14 +1,14 @@ package com.adidas.mvi.transform -import com.adidas.mvi.MviState +import com.adidas.mvi.State import com.adidas.mvi.sideeffects.SideEffects 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/src/test/kotlin/com/adidas/mvi/product/FakeProductStateTransform.kt b/mvi/src/test/kotlin/com/adidas/mvi/product/FakeProductStateTransform.kt index c25e1ad..2bf58f3 100644 --- a/mvi/src/test/kotlin/com/adidas/mvi/product/FakeProductStateTransform.kt +++ b/mvi/src/test/kotlin/com/adidas/mvi/product/FakeProductStateTransform.kt @@ -1,10 +1,12 @@ package com.adidas.mvi.product +import com.adidas.mvi.State import com.adidas.mvi.transform.StateTransform -class FakeProductStateTransform(private val state: ProductState) : StateTransform { +class FakeProductStateTransform(private val state: State) : + StateTransform { override fun reduce(currentState: ProductState): ProductState { - return state + return state.view } } diff --git a/mvi/src/test/kotlin/com/adidas/mvi/reducer/ReducerExtensionsTest.kt b/mvi/src/test/kotlin/com/adidas/mvi/reducer/ReducerExtensionsTest.kt index a7fdea1..e75ae6f 100644 --- a/mvi/src/test/kotlin/com/adidas/mvi/reducer/ReducerExtensionsTest.kt +++ b/mvi/src/test/kotlin/com/adidas/mvi/reducer/ReducerExtensionsTest.kt @@ -1,7 +1,7 @@ package com.adidas.mvi.reducer import com.adidas.mvi.Intent -import com.adidas.mvi.MviState +import com.adidas.mvi.State import com.adidas.mvi.product.ProductState import com.adidas.mvi.transform.StateTransform import io.kotest.core.spec.style.ShouldSpec @@ -15,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/transform/SideEffectTransformTest.kt b/mvi/src/test/kotlin/com/adidas/mvi/transform/SideEffectTransformTest.kt index 457cf92..254bea9 100644 --- a/mvi/src/test/kotlin/com/adidas/mvi/transform/SideEffectTransformTest.kt +++ b/mvi/src/test/kotlin/com/adidas/mvi/transform/SideEffectTransformTest.kt @@ -1,6 +1,6 @@ package com.adidas.mvi.transform -import com.adidas.mvi.MviState +import com.adidas.mvi.State import com.adidas.mvi.product.FakeProductSideEffectTransform import com.adidas.mvi.product.ProductSideEffect import com.adidas.mvi.product.ProductState @@ -14,8 +14,8 @@ class SideEffectTransformTest : ShouldSpec({ val sideEffect = ProductSideEffect.NavigateToProductDetailsSideEffect should("use mutate() function for reducing SideEffects") { - val mviState = MviState(ProductState.Loading, SideEffects()) - FakeProductSideEffectTransform(sideEffect).reduce(mviState).sideEffects shouldContainExactly + 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 index 9a6318a..52797ea 100644 --- a/mvi/src/test/kotlin/com/adidas/mvi/transform/StateTransformTest.kt +++ b/mvi/src/test/kotlin/com/adidas/mvi/transform/StateTransformTest.kt @@ -1,6 +1,6 @@ package com.adidas.mvi.transform -import com.adidas.mvi.MviState +import com.adidas.mvi.State import com.adidas.mvi.product.FakeProductStateTransform import com.adidas.mvi.product.ProductSideEffect import com.adidas.mvi.product.ProductState @@ -14,8 +14,8 @@ class StateTransformTest : ShouldSpec({ val state = ProductState.Loaded should("use mutate() function for reducing state") { - val mviState = MviState(ProductState.Loading, SideEffects()) - FakeProductStateTransform(state).reduce(mviState.state) shouldBe state + val state = State(ProductState.Loading, SideEffects()) + FakeProductStateTransform(state).reduce(state.view) shouldBe state.view } } })