fun <T> ViewModel.derived(launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else SimpleCoroutineLauncher(viewModelScope), synchronous: Boolean = true, observer: <Error class: unknown class><T>): StateFlow<T> Creates a StateFlow that computes its value based on other StateFlows via an autoRun block.
This behaves like SharingStarted.Eagerly and computes the initial value by executing the observer function immediately.
fun <T> ViewModel.derived(initial: T, started: SharingStarted = SharingStarted.Eagerly, launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else SimpleCoroutineLauncher(viewModelScope), flowTransformer: <Error class: unknown class> = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableStateFlow<Int>? = if (this is CoroutineLauncher) launcher.loading else null, observer: <Error class: unknown class><T>): StateFlow<T> fun <T> LifecycleOwner.derived(initial: T, started: SharingStarted = SharingStarted.Eagerly, launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else LifecycleCoroutineLauncher(this), flowTransformer: <Error class: unknown class> = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableStateFlow<Int>? = if (this is CoroutineLauncher) launcher.loading else null, observer: <Error class: unknown class><T>): StateFlow<T> Creates a StateFlow that computes its value based on other StateFlows via a suspendable coAutoRun block.
You can use this to compute values on-demand only via SharingStarted.WhileSubscribed.
Parameters
The initial value (until the first computation finishes).
When the value should be updated. Pass SharingStarted.WhileSubscribed to compute only on demand. Defaults to SharingStarted.Eagerly.
How changes should be executed/collected. Defaults to conflatedWorker.
The CoroutineDispatcher to use. Defaults to dispatchers.main
.
The callback which is used to track the observables.