Skip to content

Commit

Permalink
Rename MviState to State
Browse files Browse the repository at this point in the history
  • Loading branch information
sherviiin committed Aug 4, 2022
1 parent f7ca239 commit 8ebe37c
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 23 deletions.
5 changes: 0 additions & 5 deletions mvi/src/main/kotlin/com/adidas/mvi/MviState.kt

This file was deleted.

5 changes: 5 additions & 0 deletions mvi/src/main/kotlin/com/adidas/mvi/State.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.adidas.mvi

import com.adidas.mvi.sideeffects.SideEffects

public data class State<out TState, TSideEffect>(val view: TState, val sideEffects: SideEffects<TSideEffect>) : LoggableState
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,13 +14,13 @@ import kotlinx.coroutines.Dispatchers
public fun <TIntent : Intent, TInnerState : LoggableState, TAction> Reducer(
coroutineScope: CoroutineScope,
initialInnerState: TInnerState,
intentExecutor: SimplifiedIntentExecutor<TIntent, MviState<TInnerState, TAction>>,
intentExecutor: SimplifiedIntentExecutor<TIntent, State<TInnerState, TAction>>,
logger: Logger? = null,
defaultDispatcher: CoroutineDispatcher = Dispatchers.Default
): Reducer<TIntent, MviState<TInnerState, TAction>> {
): Reducer<TIntent, State<TInnerState, TAction>> {
return Reducer(
coroutineScope = coroutineScope,
initialState = MviState(initialInnerState, SideEffects()),
initialState = State(initialInnerState, SideEffects()),
intentExecutor = intentExecutor,
logger = logger,
defaultDispatcher = defaultDispatcher
Expand Down
Original file line number Diff line number Diff line change
@@ -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<TState, TSideEffect> :
StateTransform<MviState<TState, TSideEffect>> {
StateTransform<State<TState, TSideEffect>> {

protected abstract fun mutate(sideEffects: SideEffects<TSideEffect>): SideEffects<TSideEffect>

final override fun reduce(currentState: MviState<TState, TSideEffect>): MviState<TState, TSideEffect> {
final override fun reduce(currentState: State<TState, TSideEffect>): State<TState, TSideEffect> {
val sideEffects = currentState.sideEffects
return currentState.copy(sideEffects = mutate(sideEffects))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ProductState> {
class FakeProductStateTransform(private val state: State<ProductState, ProductSideEffect>) :
StateTransform<ProductState> {

override fun reduce(currentState: ProductState): ProductState {
return state
return state.view
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,12 +15,12 @@ class ReducerExtensionsTest : ShouldSpec({
coroutineScope = TestScope(),
initialInnerState = ProductState.Loading,
intentExecutor = { _: Intent ->
emptyFlow<StateTransform<MviState<ProductState, Unit>>>()
emptyFlow<StateTransform<State<ProductState, Unit>>>()
}
)

should("The initial inner state should be Loading") {
reducer.state.value.state shouldBe ProductState.Loading
reducer.state.value.view shouldBe ProductState.Loading
}
}
})
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,8 +14,8 @@ class SideEffectTransformTest : ShouldSpec({
val sideEffect = ProductSideEffect.NavigateToProductDetailsSideEffect

should("use mutate() function for reducing SideEffects") {
val mviState = MviState(ProductState.Loading, SideEffects<ProductSideEffect>())
FakeProductSideEffectTransform(sideEffect).reduce(mviState).sideEffects shouldContainExactly
val state = State(ProductState.Loading, SideEffects<ProductSideEffect>())
FakeProductSideEffectTransform(sideEffect).reduce(state).sideEffects shouldContainExactly
listOf<ProductSideEffect>(sideEffect)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,8 +14,8 @@ class StateTransformTest : ShouldSpec({
val state = ProductState.Loaded

should("use mutate() function for reducing state") {
val mviState = MviState(ProductState.Loading, SideEffects<ProductSideEffect>())
FakeProductStateTransform(state).reduce(mviState.state) shouldBe state
val state = State(ProductState.Loading, SideEffects<ProductSideEffect>())
FakeProductStateTransform(state).reduce(state.view) shouldBe state.view
}
}
})

0 comments on commit 8ebe37c

Please sign in to comment.