All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.LoggingUpdate.kt Maven / Gradle / Ivy

package kt.mobius

import kt.mobius.internal_util.Throwables

class LoggingUpdate internal constructor(
    private val actualUpdate: Update,
    private val logger: MobiusLoop.Logger
) : Update {

    override fun update(model: M, event: E): Next {
        logger.beforeUpdate(model, event)
        val result = safeInvokeUpdate(model, event)
        logger.afterUpdate(model, event, result)
        return result
    }

    private fun safeInvokeUpdate(model: M, event: E): Next {
        try {
            return actualUpdate.update(model, event)
        } catch (e: Exception) {
            logger.exceptionDuringUpdate(model, event, e)
            throw Throwables.propagate(e)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy