-
public final class ContainerHostExtensionsKt
-
-
Method Summary
Modifier and Type Method Description final static <STATE extends Any, SIDE_EFFECT extends Any> Unitobserve(ContainerHost<STATE, SIDE_EFFECT> $self, LifecycleOwner lifecycleOwner, Lifecycle.State lifecycleState, SuspendFunction1<STATE, Unit> state, SuspendFunction1<SIDE_EFFECT, Unit> sideEffect)Observe Container.stateFlow and Container.sideEffectFlow correctly on Android in one-line of code. -
-
Method Detail
-
observe
final static <STATE extends Any, SIDE_EFFECT extends Any> Unit observe(ContainerHost<STATE, SIDE_EFFECT> $self, LifecycleOwner lifecycleOwner, Lifecycle.State lifecycleState, SuspendFunction1<STATE, Unit> state, SuspendFunction1<SIDE_EFFECT, Unit> sideEffect)
Observe Container.stateFlow and Container.sideEffectFlow correctly on Android in one-line of code. These streams are observed when the view is in Lifecycle.State.STARTED.
In Activities, call from onCreate, where viewModel is a ContainerHost:
viewModel.observe(this, state = ::state, sideEffect = ::sideEffect)In Fragments, call from onViewCreated, where viewModel is a ContainerHost:
viewModel.observe(viewLifecycleOwner, state = ::state, sideEffect = ::sideEffect)
-
-
-
-