icerockdev / moko-mvvm

Model-View-ViewModel architecture components for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
1k stars 95 forks source link

Add MutableLiveData empty constructor. #52

Closed georgiscoolman closed 3 years ago

georgiscoolman commented 4 years ago

Thank you for nice mpp mvvm solution! It will be great if MutableLiveData will have empty constructor. It will let developer to handle case when there is no initial data. And then post updates when some process will be done.

Alex009 commented 4 years ago

hello! thanks for feedback!

you can select you own type with support of nullability exactly for your use-case, so if you not want initial data - just create MutableLiveData<Int?>(initalValue = null).

we can't add empty constructor because class is generic with strong generic type (if we use LiveData<Int> it 100% not have null in any time).

theGlenn commented 3 years ago

With a nullable, isn't null an initial value that would be propagated through the livedata chain ?

Alex009 commented 3 years ago

null will be propagated. also if you just call liveData.value you got null too. so with strong generic type we can't do MutableLiveData<Int>() - we broke api in this case, because while you not set some value in storage will be null value.