Group Group Group Group Group Group Group Group Group

Beginning RxKotlin · Observables and Subjects in Practice, Part 2 | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/7419-beginning-rxkotlin/lessons/12

Hi Macsimus,

I was going through the video tutorial and I saw you passing fragment as a method parameter in SharedViewModel. Is it a good practice to expose view to a viewmodel ?

Thank you for the question, Sagar. Here, in this context we’re just using SharedViewModel to allow the flow of events between the photo chooser and its host activity. It would also have been possible to pass the Observable in as the method parameter instead of the fragment, and perhaps that would have been better. Thanks again for the question!

1 Like

wouldnt the idea of passing the fragment to the sharedViewModel and the frament having an instance of the sharedViewModel be technically considered a circular dependency?

@macsimus Can you please help with this when you get a chance? Thank you - much appreciated! :]

I agree. You could however pass the Observable itself and avoid passing UI components to the VM.
fun subscribeSelectedPhotos(photoPickerObservable: Observable<Photo>)

@wwmobileteam Thank you for sharing this - much appreciated!