commonMain.com.copperleaf.ballast.test.internal.vm.ViewModelWrapper.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.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