KotlinBloc icon indicating copy to clipboard operation
KotlinBloc copied to clipboard

BlocViewModel?

Open firefinchdev opened this issue 3 years ago • 4 comments

I really liked your implementation of Bloc in kotlin.

ViewModel is finely integrated with Activities (retention on activity recreate, etc) and other Android stuff in general. Also ViewModel is responsible for holding the ui state, and reacting to ui actions (just like Bloc).

So, a BlocViewModel based on AndroidViewModel/ViewModel would be great and really useful.

BlocViewModel would be a AndroidViewModel/ViewModel with all capabilities of Bloc.

Your thoughts?

firefinchdev avatar Jan 26 '22 13:01 firefinchdev

I think it should use viewmodel as you have suggested. For me the most important reason to use viewmodel is to use hilt.

zainulhassan815 avatar Feb 16 '22 17:02 zainulhassan815

I like this suggestion - I'll look into it!

ptrbrynt avatar Feb 21 '22 08:02 ptrbrynt

I like this suggestion - I'll look into it!

Amazing. This will be really helpful as we will be able to use hilt, scopes and other cool stuff. Plus if google adds more features to viewmodel, we will be able to adopt them easily. Looking forward for an update.

zainulhassan815 avatar Feb 21 '22 08:02 zainulhassan815

I have looked into the library and the it can be achieved by exteneding BlocBase with ViewModel.

abstract class BlocBase<State>(initial: State)

But another serious issue arises here that KotlinBloc which is platform independent, becomes specific to android only. Maybe a separate library like com.github.ptrbrynt.KotlinBloc:viewmodel which would be specific to android. It's a suggestion. There might be other solutions to this as well.

zainulhassan815 avatar Apr 20 '22 11:04 zainulhassan815