removing debug log option for state changes

This commit is contained in:
Adam Brown 2022-11-02 14:45:08 +00:00
parent 68674aeaab
commit 87083b07dd
1 changed files with 1 additions and 9 deletions

View File

@ -4,7 +4,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlin.reflect.KClass
fun <S> createStore(reducerFactory: ReducerFactory<S>, coroutineScope: CoroutineScope, log: Boolean = false): Store<S> {
fun <S> createStore(reducerFactory: ReducerFactory<S>, coroutineScope: CoroutineScope): Store<S> {
val subscribers = mutableListOf<(S) -> Unit>()
var state: S = reducerFactory.initialState()
return object : Store<S> {
@ -13,17 +13,9 @@ fun <S> createStore(reducerFactory: ReducerFactory<S>, coroutineScope: Coroutine
override fun dispatch(action: Action) {
coroutineScope.launch {
if (log) println("??? dispatch $action")
state = reducer.reduce(action).also { nextState ->
if (nextState != state) {
if (log) {
println("??? action: $action result...")
println("??? current: $state")
println("??? next: $nextState")
}
subscribers.forEach { it.invoke(nextState) }
} else {
if (log) println("??? action: $action skipped, no change")
}
}
}