commonMain.com.copperleaf.ballast.test.internal.vm.TestViewModel.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ballast-test-js Show documentation
Show all versions of ballast-test-js Show documentation
Opinionated Kotlin multiplatform MVI library
package com.copperleaf.ballast.test.internal.vm
import com.copperleaf.ballast.BallastInterceptor
import com.copperleaf.ballast.BallastViewModel
import com.copperleaf.ballast.InputFilter
import com.copperleaf.ballast.InputHandler
import com.copperleaf.ballast.InputStrategy
import com.copperleaf.ballast.core.DefaultViewModelConfiguration
import com.copperleaf.ballast.core.LoggingInterceptor
import com.copperleaf.ballast.internal.BallastViewModelImpl
import kotlinx.coroutines.CompletableDeferred
internal class TestViewModel internal constructor(
internal val logger: (String) -> Unit,
internal val testInterceptor: TestInterceptor,
internal val otherInterceptors: List, Events, State>>,
internal val initialState: State,
internal val inputHandler: InputHandler,
internal val filter: InputFilter, Events, State>?,
internal val inputStrategy: InputStrategy,
name: String,
internal val impl: BallastViewModelImpl, Events, State> = BallastViewModelImpl(
DefaultViewModelConfiguration(
initialState = initialState,
inputHandler = TestInputHandler(logger, inputHandler),
interceptors = listOf(
*otherInterceptors.toTypedArray(),
LoggingInterceptor(
logMessage = { logger(it) },
logError = { logger(it.message ?: "") },
),
testInterceptor,
),
filter = filter,
inputStrategy = inputStrategy,
name = name,
),
),
) : BallastViewModel, Events, State> by impl {
sealed class Inputs {
data class ProcessInput(
val normalInput: BaseInputs,
val processingStarted: CompletableDeferred,
) : Inputs()
data class AwaitInput(
val normalInput: BaseInputs,
val processingFinished: CompletableDeferred,
) : Inputs()
data class TestCompleted(
val processingFinished: CompletableDeferred
) : Inputs()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy