BlocOwner

interface BlocOwner<out State : Any, in Action : Any, SideEffect : Any, Proposal : Any>

A class is a BlocOwner if it holds and exposes a Bloc.

Using extension functions this interface allows the use of the MVVM+ syntax for defining thunk { }, sideEffect { } and reduce { } / reduceAnd { }, e.g.:

fun onClicked(item: Item) = sideEffect {
ItemList.OpenItem(list)
}

If BlocOwner isn't implemented (e.g. because the Bloc shouldn't be visible outside the class), the syntax is:

fun onClicked(item: Item) = bloc.sideEffect {
ItemList.OpenItem(list)
}

If a component is a BlocOwner it doesn't have to implement BlocObservableOwner since a BlocOwner can also be observed (it has an observable Bloc) and every extension functions for BlocObservableOwner is also implemented for BlocOwner.

Functions

Link copied to clipboard
open infix fun Proposal.and(sideEffect: SideEffect): Effect<Proposal, SideEffect>
open infix fun SideEffect.and(sideEffect: SideEffect): List<SideEffect>
Link copied to clipboard
Link copied to clipboard

Submit a Reducer without side effects to a BlocOwner/Bloc to be run. The reducer will receive the state but no action (since it was triggered "manually", not by sending an action to the Bloc).

Link copied to clipboard

Submit a Reducer with side effects to a BlocOwner/Bloc to be run. The reducer will receive the state but no action (since it was triggered "manually", not by sending an action to the Bloc).

Link copied to clipboard

Submit a SideEffect to a BlocOwner/Bloc to be emitted. The side effect will receive the state but no action (since it was triggered "manually", not by sending an action to the Bloc).

Link copied to clipboard
fun <State : Any, Action : Any, SideEffect : Any, Proposal : Any> BlocOwner<State, Action, SideEffect, Proposal>.subscribe(lifecycleOwner: LifecycleOwner, state: suspend (state: State) -> Unit? = null, sideEffect: suspend (sideEffect: SideEffect) -> Unit? = null)

Same as above for a BlocOwner

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):

Link copied to clipboard

Submit a Thunk to a BlocOwner/Bloc to be run. The thunk will receive the dispatch and the getState function but no action (since it was triggered "manually", not by sending an action to the Bloc). The dispatch function dispatches to the first matching thunk/reducer/side-effect in the Bloc.

Properties

Link copied to clipboard
abstract val bloc: Bloc<State, Action, SideEffect>