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

commonMain.com.copperleaf.ballast.test.internal.vm.TestViewModel.kt Maven / Gradle / Ivy

There is a newer version: 4.2.1
Show newest version
package com.copperleaf.ballast.test.internal.vm

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.DelegatingInterceptor
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 interceptor: TestInterceptor,
    internal val initialState: State,
    internal val inputHandler: InputHandler,
    internal val filter: InputFilter, Events, State>?,
    internal val inputStrategy: InputStrategy,
    internal val impl: BallastViewModelImpl, Events, State> = BallastViewModelImpl(
        initialState,
        DefaultViewModelConfiguration(
            inputHandler = TestInputHandler(logger, inputHandler),
            interceptor = DelegatingInterceptor(
                interceptor,
                LoggingInterceptor(
                    logMessage = { logger(it) },
                    logError = { logger(it.message ?: "") },
                )
            ),
            filter = filter,
            inputStrategy = inputStrategy,
        ),
    ),
) : 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