Package 

Class ContainerHostExtensionsKt

    • Method Summary

      Modifier and Type Method Description
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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)