Hello to everyone,
I'm trying to create a xplatform app (as most of us) and I'm having some doubts about how to approach the ViewModel life cycle using MvvmCross.
I will pose several questions to you in order to see how are you guys managing this matter:
- IMvxBundle only accepts strings for all its items as it is some sort of wrapper of IDictionary<string, string>. On the other hand, the SaveState pattern explained by @slodge here doesn't seem capable of accepting objects with complex properties as arrays or generic lists as it tries to convert the passed object into a IMvxBundle, and the parsing of complex types directly ignores these kind of properties.
How do you handle this? Do you use the SaveStateToBundle method instead and serialize the complex properties into JSON? Any other approach? Maybe a custom plugin?
- According to the previous @slodge documentation you can use any of these methods to persist any object you want and then the ReloadState method will be called in your viewmodel. However, looking at the source code I see that even if you have created a SaveState method the only hooks you have to do your saving stuff are located on the view (SaveStateBundle) and in the same viewmodel (SaveStateToBundle).
I don't see the point of going down to the view to do the saving part as it would seem that we're forced to extend the mvx view class for every platform. Maybe I'm missing something :P
On the other hand, when loading a view the LoadStateBundle method is called always returning null. This method is supposed to be the one generating a IMvxBundle which later will be used by the ReloadState method in our viewmodel. Again, I'm forced to do all my recovery stuff in the view.
In this case, what do you do in your projects? Do you rehydrate your viewmodels in the Init method or even Start? Do you extend your views for every platform?
Please, bear in mind I'm new to the MvvmCross framework so maybe I haven't see the whole picture. That's why I'm asking for advice to all of you.
I would also like to say that I think that MvvmCross is an awesome framework filled with a lot of hidden gems (e.g: MVxCommandCollectionBuilder).
Thank you very much!!
-- Roberto.