Package 

Class CollectStateKt

    • Method Detail

      • collectState

         final static <State extends Any> Job collectState(Fragment $self, StateOwner<State> stateOwner, Lifecycle.State lifecycleState, Function1<State, Unit> block)

        Collect emissions from a StateHolder launched and scoped to Fragment.getViewLifecycleOwner.

        Example:

        class MyFragment : Fragment() {
            private val viewModel by viewModels<MyViewModel>()
        
            override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
                super.onViewCreated(view, savedInstanceState)
        
                collectState(viewModel) { state ->
                    // Handle state
                }
            }
        }
        Parameters:
        lifecycleState - The Lifecycle.State to launch the coroutine.
        block - Lambda to handle the state emissions.
      • collectState

         final static <State extends Any, T extends Any> Job collectState(Fragment $self, StateOwner<State> stateOwner, Function1<State, T> selector, Lifecycle.State lifecycleState, Function1<T, Unit> block)

        Collect emissions of a selected property of State scoped to Fragment.getViewLifecycleOwner.

        Example:

        class MyFragment : Fragment() {
            private val viewModel by viewModels<MyViewModel>()
        
            override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
                super.onViewCreated(view, savedInstanceState)
        
                collectState(viewModel, { it.myProperty }) { myProperty ->
                    // Handle myProperty
                }
            }
        }
        Parameters:
        selector - Lambda to select a property of State to collect.
        lifecycleState - The Lifecycle.State to launch the coroutine.
        block - Lambda to handle the selected property emissions.
      • collectState

         final static <State extends Any> Job collectState(FragmentActivity $self, StateOwner<State> stateOwner, Lifecycle.State lifecycleState, Function1<State, Unit> block)

        Collect emissions from a StateHolder launched and scoped to FragmentActivity lifecycle.

        Example:

        class MyActivity : FragmentActivity() {
            private val viewModel by viewModels<MyViewModel>()
        
            override fun onCreate(savedInstanceState: Bundle?) {
                super.onCreate(savedInstanceState)
        
                collectState(viewModel) { state ->
                    // Handle state
                }
            }
        }
        Parameters:
        lifecycleState - The Lifecycle.State to launch the coroutine.
        block - Lambda to handle the state emissions.
      • collectState

         final static <State extends Any, T extends Any> Job collectState(FragmentActivity $self, StateOwner<State> stateOwner, Function1<State, T> selector, Lifecycle.State lifecycleState, Function1<T, Unit> block)

        Collect emissions of a selected property of State scoped to FragmentActivity lifecycle.

        Example:

        class MyActivity : FragmentActivity() {
            private val viewModel by viewModels<MyViewModel>()
        
            override fun onCreate(savedInstanceState: Bundle?) {
                super.onCreate(savedInstanceState)
        
                collectState(viewModel, { it.myProperty }) { myProperty ->
                    // Handle myProperty
                }
            }
        }
        Parameters:
        selector - Lambda to select a property of State to collect.
        lifecycleState - The Lifecycle.State to launch the coroutine.
        block - Lambda to handle the selected property emissions.
      • collectState

         final static <State extends Any> Job collectState(StateOwner<State> $self, LifecycleOwner lifecycleOwner, Lifecycle.State lifecycleState, Function1<State, Unit> block)

        Collect emissions from a StateHolder launched and scoped to the lifecycleOwner.

        Parameters:
        lifecycleOwner - LifecycleOwner to launch coroutine from.
        lifecycleState - The Lifecycle.State to launch the coroutine.
        block - Lambda to handle the state emissions.
      • collectState

         final static <State extends Any, T extends Any> Job collectState(StateOwner<State> $self, LifecycleOwner lifecycleOwner, Function1<State, T> selector, Lifecycle.State lifecycleState, Function1<T, Unit> block)

        Collect emissions of a selected property of State.

        Parameters:
        lifecycleOwner - LifecycleOwner to launch coroutine from.
        selector - Lambda to select a property of State to collect.
        lifecycleState - The Lifecycle.State to launch the coroutine.
        block - Lambda to handle the selected property emissions.