icerockdev / moko-mvvm

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

How to extend MutableLiveData #80

Closed mathemandy closed 3 years ago

mathemandy commented 3 years ago

I am trying to extend MutableLivedata to support SingleLiveEvent for a feature I need. but the api is restricting how I can conveniently use the class

Alex009 commented 3 years ago

hi @mathemandy ! MutableLiveData is open class, so you can extend from it. what restrictions limit you?

also we use EventsDispatcher as replace for SingleLiveEvent - are you sure that you need SingleLiveEvent? maybe version with interface will be good? https://github.com/icerockdev/moko-mvvm/blob/master/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/sample2/EventsViewModel.kt#L15

https://github.com/icerockdev/moko-mvvm/blob/master/sample/android-app/src/main/java/com/icerockdev/app/sample2/EventsActivity.kt#L37