childReactiveState
fun <E : ErrorEvents, P : ReactiveState<out E>, RS : ReactiveState<E>> P.childReactiveState(block: () -> RS): ReadOnlyProperty<Any?, RS>
Creates and attaches a child ReactiveState.
This merges the child's ReactiveState.eventNotifier and ReactiveState.loading into the parent.
Example:
// The parent has to also implement the child events
interface ParentEvents : ChildEvents {
fun onSomeEvent()
}
class ParentViewModel(scope: CoroutineScope) : BaseReactiveState<ParentEvents>(scope) {
val childViewModel by childReactiveState { ChildViewModel(scope) }
}
interface ChildEvents : ErrorEvents {
fun onSomeChildEvent()
}
class ChildViewModel(scope: CoroutineScope) : BaseReactiveState<ChildEvents>(scope) {
init {
launch {
// ...
eventNotifier {
onSomeChildEvent()
}
}
}
}
Content copied to clipboard