Skip to content

Commit

Permalink
feat: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kramlex committed Nov 26, 2023
1 parent a0eb755 commit 2b3393f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ androidGradle = "7.4.2"
androidLifecycleVersion = "2.6.2"
kotlinxCoroutines = "1.7.3"

mvm = "0.0.7"
mvm = "0.0.8"

[libraries]

Expand Down
6 changes: 3 additions & 3 deletions mvi/src/commonMain/kotlin/app/meetacy/vm/mvi/StateHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public abstract class StateHolder<TState, TEffect> {
public abstract val effects: CFlow<TEffect>
public abstract val states: CStateFlow<TState>

public abstract suspend fun accept(intent: Intent<TState, TEffect>)
public abstract suspend fun accept(effect: TEffect)
public abstract fun accept(newState: TState)
internal abstract suspend fun accept(intent: Intent<TState, TEffect>)
internal abstract suspend fun perform(effect: TEffect)
internal abstract fun accept(newState: TState)
}
2 changes: 1 addition & 1 deletion mvi/src/commonMain/kotlin/app/meetacy/vm/mvi/StateHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public fun <TState, TEffect> StateHost<TState, TEffect>.holder(
}
}

override suspend fun accept(effect: TEffect) {
override suspend fun perform(effect: TEffect) {
_effects.send(effect)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import kotlinx.coroutines.launch

public abstract class StateHostedViewModel<TState, TEffect>: ViewModel(), StateHost<TState, TEffect> {

protected val state: TState get() = holder.states.value

protected fun viewModelScopeLaunch(block: suspend CoroutineScope.() -> Unit) {
viewModelScope.launch(block = block)
}
Expand All @@ -23,7 +25,7 @@ public abstract class StateHostedViewModel<TState, TEffect>: ViewModel(), StateH
holder.accept(holder.states.value.transform())
}

protected fun accept(effect: TEffect) {
viewModelScope.launch { holder.accept(effect) }
protected fun perform(effect: TEffect) {
viewModelScope.launch { holder.perform(effect) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import app.meetacy.vm.extension.launchIn
class SomeViewModel: StateHostedViewModel<SomeViewModel.State, SomeViewModel.Effect>() {

override val holder: StateHolder<State, Effect> = holder(State())

data class State(val isLoading: Boolean = true)

sealed interface Effect
Expand Down

0 comments on commit 2b3393f

Please sign in to comment.