//reactivestate-core/com.ensody.reactivestate/derived
derived¶
[common]\ fun <T> derived(synchronous: Boolean = true, cache: Boolean = true, observer: AutoRunCallback<T>): StateFlow<T>
Creates a StateFlow that computes its value based on other StateFlows via an autoRun block.
This variant doesn’t need a CoroutineScope/CoroutineLauncher.
Parameters¶
common
synchronous | Whether .value access synchronously recomputes even if someone collects. Defaults to true . |
cache | Caching of StateFlow.value expensive computations while nobody collects. Defaults to true . |
[common]\ fun <T> CoroutineLauncher.derived(synchronous: Boolean = true, cache: Boolean = synchronous, observer: AutoRunCallback<T>): StateFlow<T>
Creates a StateFlow that computes its value based on other StateFlows via an autoRun block.
Parameters¶
common
synchronous | Whether .value access synchronously recomputes even if someone collects. Defaults to true . |
cache | Caching of StateFlow.value expensive computations while nobody collects. Defaults to true . |
[common]\ fun <T> CoroutineScope.derived(launcher: CoroutineLauncher = SimpleCoroutineLauncher(this), synchronous: Boolean = true, cache: Boolean = synchronous, observer: AutoRunCallback<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.
[common]\ fun <T> CoroutineLauncher.derived(initial: T, started: SharingStarted = SharingStarted.Eagerly, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableValueFlow<Int>? = loading, observer: CoAutoRunCallback<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¶
common
initial | The initial value (until the first computation finishes). |
started | When the value should be updated. Pass SharingStarted.WhileSubscribed to compute only on demand. Defaults to SharingStarted.Eagerly. |
flowTransformer | How changes should be executed/collected. Defaults to conflatedWorker. |
dispatcher | The CoroutineDispatcher to use. Defaults to dispatchers.main . |
withLoading | Tracks loading state for the (re-)computation. Defaults to CoroutineLauncher.loading. |
observer | The callback which is used to track the observables. |
[common]\ fun <T> CoroutineScope.derived(initial: T, started: SharingStarted = SharingStarted.Eagerly, launcher: CoroutineLauncher = SimpleCoroutineLauncher(this), flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableValueFlow<Int>? = null, observer: CoAutoRunCallback<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¶
common
initial | The initial value (until the first computation finishes). |
started | When the value should be updated. Pass SharingStarted.WhileSubscribed to compute only on demand. Defaults to SharingStarted.Eagerly. |
launcher | The CoroutineLauncher to use. |
flowTransformer | How changes should be executed/collected. Defaults to conflatedWorker. |
dispatcher | The CoroutineDispatcher to use. Defaults to dispatchers.main . |
withLoading | Tracks loading state for the (re-)computation. Defaults to null . |
observer | The callback which is used to track the observables. |