BaseViewModel

abstract class BaseViewModel<S : Any, E : Any, A : Any>(initial: S) : ViewModel

MVI base. S = UiState, E = Effect, A = user Action.

Two effect channels with distinct delivery contracts:

  • emitEffect → a buffered Channel consumed exactly once by the screen's LaunchedEffect. Use for navigation, toasts, one-shot dialogs, things that must fire once and never replay.

  • emitBroadcast → a SharedFlow (no replay, drops oldest on overflow) that survives config change and is delivered to whatever collector is active. Use for fire-and-forget signals where a missed emission is acceptable but new collectors should still receive subsequent ones.

Constructors

Link copied to clipboard
constructor(initial: S)

Properties

Link copied to clipboard
val broadcast: SharedFlow<E>
Link copied to clipboard
val effect: Flow<E>
Link copied to clipboard
val state: StateFlow<S>

Functions

Link copied to clipboard
expect open fun addCloseable(closeable: AutoCloseable)
expect fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard
expect fun <T : AutoCloseable> getCloseable(key: String): T?
Link copied to clipboard
abstract fun onAction(action: A)