updateWith

context(viewModel: ViewModel)
inline fun <T : Any> MutableStateFlow<UiState<T>>.updateWith(crossinline operation: suspend T.() -> Result<Unit>)(source)

Launches a Result-returning action in the context ViewModel's scope without replacing data.

A call observing loading = true is dropped; calls queued before the coroutine sets that flag can overlap. Starting clears the old error event. Returned success clears loading; returned failure also stores its throwable in OneTimeEvent. Current data is preserved on both paths.

Thrown exceptions and cancellation are not caught and can leave loading true. The operation receives a data snapshot, but completion does not write it back. This helper returns no result or Job. Use it, for example, when deleting an item through a repository returning Result<Unit>.

Parameters

operation

Suspend action receiving current data and returning Result of Unit.

Type Parameters

T

The screen-data type.

See also