Bloc
The core class of the framework. (can't be an interface or the generic types are erased in Swift)
A Bloc implements the app's business logic. It processes event data (called Action) from the view / ui component and:
updates State according to its business rules and emits the updated State to be consumed by the view / ui component.
optionally creates SideEffect(s) which can be consumed by the view / ui component (e.g. for navigation) or by other consumers (analytics events, logging etc.).
A Bloc is a BlocState (allowing us to use a Bloc as BlocState and create composable Blocs):
a StateStream
emitting state a Sink
accepting actions that might trigger state changes
A Bloc has a SideEffectStream
Functions
Converts a Bloc to a BlocState.
This observe function is used for iOS to ensure generic types aren't erased. It's the equivalent of the subscribe extension function for Android. Note: the state and sideEffect parameters are of type BlocObserver which is different from the signature used in the Android observe function.
Submit a Reducer without side effects to a 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).
Submit a Reducer with side effects to a 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).
Submit a SideEffect to a 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). Note: the proposal is irrelevant for sideEffect so we set it to Unit
Same as above for a Bloc
Subscribes to the state and side effects streams of a Bloc.
Submit a Thunk to a 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.
If a components implements the BlocObservableOwner interface it needs to provide
Same as above but combine just two Blocs to BlocObservable.