BlocComponent
The BlocComponent class is very similar to BlocHolder
. The only difference is that the latter always wraps a Bloc
while the former wraps an arbitrary component that needs a BlocContext
to be instantiated, e.g.:
struct PostListView: View {
private let component = BlocComponent<PostsComponent> { PostsComponentImpl(context: $0) }
class PostsComponentImpl(context: BlocContext) {
val bloc by lazy {
bloc<PostsRootState, PostsAction>(context, blocState) {
// build the bloc
}
}
tip
In both cases the generic types will be preserved.
In the case of a BlocHolder
, the BlocHolder
itself declares the generic types (and also the bloc it wraps).
In the case of a BlocComponent
, the wrapped component or rather the bloc it contains declares the generic types.