OnInit

A mechanism for ViewModel initialization-time tasks like repository cache refresh. Use via ContextualOnInit.

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 (or the simpler CoroutineLauncher.triggerOnInit) 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
abstract fun trigger(source: CoroutineLauncher)
Link copied to clipboard
abstract fun unobserve(block: OnInitContext.() -> Unit)