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

commonMain.com.copperleaf.ballast.test.internal.vm.ViewModelWrapper.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 kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.ChannelResult
import kotlinx.coroutines.channels.SendChannel
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.selects.SelectClause2

internal class ViewModelWrapper(
    private val delegate: BallastViewModel, Events, State>,
) : BallastViewModel {

    override val name: String
        get() = delegate.name

    @ExperimentalCoroutinesApi
    override val isClosedForSend: Boolean
        get() = delegate.isClosedForSend

    override val onSend: SelectClause2>
        get() = error("cannot call onSend on ViewModelWrapper")

    override fun close(cause: Throwable?): Boolean {
        return delegate.close(cause)
    }

    @ExperimentalCoroutinesApi
    override fun invokeOnClose(handler: (cause: Throwable?) -> Unit) {
        delegate.invokeOnClose(handler)
    }

    override suspend fun send(element: Inputs) {
        delegate.send(TestViewModel.Inputs.ProcessInput(element, CompletableDeferred()))
    }

    override fun trySend(element: Inputs): ChannelResult {
        return delegate.trySend(TestViewModel.Inputs.ProcessInput(element, CompletableDeferred()))
    }

    override fun observeStates(): StateFlow {
        return delegate.observeStates()
    }

    override fun onCleared() {
        delegate.onCleared()
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy