subscribe

fun <State : Any, Action : Any, SideEffect : Any> Bloc<State, Action, SideEffect>.subscribe(lifecycle: Lifecycle, state: suspend (state: State) -> Unit? = null, sideEffect: suspend (sideEffect: SideEffect) -> Unit? = null)

Subscribes to the state and side effects streams of a Bloc.

The subscription is tied to the lifecycle of the caller. The subscription starts with onStart() and is cancelled with onStop().


fun <State : Any, Action : Any, SideEffect : Any, Proposal : Any> BlocOwner<State, Action, SideEffect, Proposal>.subscribe(lifecycle: Lifecycle, state: suspend (state: State) -> Unit? = null, sideEffect: suspend (sideEffect: SideEffect) -> Unit? = null)

Call from a component to observe state and side effect updates in a BlocOwner (BlocOwner in Android is typically a ViewModel, the observing component a Fragment or an Activity):

component.subscribe(lifecycle, state = ::render, sideEffect = ::sideEffect)

Note: there are extension functions for Fragments and Activities to get an Essenty lifecycle, so a call typically looks like:

component.subscribe(this, state = ::render, sideEffect = ::sideEffect)

fun <State : Any, SideEffect : Any> BlocObservableOwner<State, SideEffect>.subscribe(lifecycle: Lifecycle, state: suspend (state: State) -> Unit? = null, sideEffect: suspend (sideEffect: SideEffect) -> Unit? = null)

Analogous call for BlocObservableOwner