dave08
02/03/2020, 4:13 PMlateinit var that's initialized when the viewmodel is injected in the Fragment... but that's a bit of a brittle way to do things?satyan
02/03/2020, 4:14 PMdave08
02/03/2020, 4:16 PMMutableLiveData from the ViewModel that the view can post to? It wouldn't have been a bad idea... but in my case, I need to combine that Flow with one I'm getting from a repository...satyan
02/03/2020, 4:21 PMdave08
02/03/2020, 4:24 PMContext from my VM to make unit tests... having a Flow exposed instead of BroadcastReceiver code makes it easy to mock... I guess for now a lateinit var is the way to go... just wondering what everybody else does in this case.
Your idea for MutableLiveData might also come in handy in other situations... thanks!satyan
02/03/2020, 4:30 PMMutableLiveData.
I’m not sure it is a good practice to push from the view to the ViewModel using a MutableLiveData.
Just expose a method in your view model 🤷dave08
02/03/2020, 4:37 PMLiveData is really to manage View lifecycles...Hakob Astvacatryan
02/03/2020, 4:58 PMdave08
02/03/2020, 5:40 PMlateinit var though... since I need to register that BroadcastReceiver ...?dave08
02/03/2020, 5:41 PMViewModel, I'd need to inject the class implementing the interface...Hakob Astvacatryan
02/03/2020, 5:42 PMHakob Astvacatryan
02/03/2020, 5:42 PMvaldave08
02/03/2020, 5:44 PMvar containing the Flow needs to be initialized in onCreateView() of the Fragment so that the viewmodel can listen to it...dave08
02/03/2020, 5:45 PMonCreateView() or just having a lateinit var just does the same?Hakob Astvacatryan
02/03/2020, 5:46 PMonCreateView?dave08
02/03/2020, 5:49 PMContext to register that receiver with the lifecycle of the Fragment ...Hakob Astvacatryan
02/03/2020, 5:51 PMHakob Astvacatryan
02/03/2020, 5:55 PMdave08
02/03/2020, 5:57 PMHakob Astvacatryan
02/03/2020, 5:59 PMViewModel for testing purposes it worth 🙂dave08
02/03/2020, 6:07 PMdave08
02/03/2020, 6:08 PMAnastasia Finogenova
02/03/2020, 10:03 PM