OnInit

A mechanism for ReactiveViewModel initialization-time tasks like repository cache refresh.

With observe you get notified when the ViewModel is ready. On the provided OnInitContext you can launch coroutines which are associated with your observer. If any of the coroutines fail the state will reflect that and you can run trigger again for only the failing observers.

Types

Link copied to clipboard
sealed interface State

Properties

Link copied to clipboard
abstract val state: StateFlow<OnInit.State>

The initialization state.

Functions

Link copied to clipboard
abstract fun observe(block: OnInitContext.() -> Unit)
Link copied to clipboard

Triggers all observers, even completed ones, from scratch.

Link copied to clipboard
abstract fun setInitializingState()

Marks all completed observers as not-yet-complete, so trigger will run them again.

Link copied to clipboard
abstract fun trigger()

Starts any not yet finished observers. This can also be used for retry if some observer fails.

Link copied to clipboard
abstract fun unobserve(block: OnInitContext.() -> Unit)