commonMain.net.humans.kmm.mvi.Logging.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mvi-core Show documentation
Show all versions of mvi-core Show documentation
Simple and concise implementation of Redux/MVI approach by Humans.
The newest version!
package net.humans.kmm.mvi
import co.touchlab.kermit.Logger
internal fun Logger.logReduce(msg: M, prevState: S, state: S, effects: List) {
d { "Begin reduce:" }
d {
prevState.logReduxClassName() +
", ${msg.logReduxClassName()} -> " +
state.logReduxClassName() +
if (effects.isNotEmpty()) ", ${effects.joinToString { it.logReduxClassName() }}" else ""
}
d { "End reduce" }
}
internal fun Logger.logReduce(prevState: S, state: S, msg: M) {
d { "Begin reduce:" }
d { "${prevState.logReduxClassName()}, ${msg.logReduxClassName()} -> ${state.logReduxClassName()}" }
d { "End reduce" }
}
private fun Any?.logReduxClassName(): String {
val className = this?.run { this::class.qualifiedName } ?: ""
return className.substringAfter("Redux.")
}
@Suppress("FunctionName")
fun Any.LoggingErrorHandler(msg: String = "Error occurred"): ErrorHandler {
return { throwable ->
Logger.withTag(msg).e(this::class.simpleName.orEmpty(), throwable)
}
}