Skip to content

Commit

Permalink
removing debug log option for state changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ouchadam committed Nov 2, 2022
1 parent 68674ae commit 87083b0
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions domains/state/src/main/kotlin/app/dapk/state/State.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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")
}
}
}
Expand Down

0 comments on commit 87083b0

Please sign in to comment.