Should each view have its own viewmodel, or should one big VM connect small views


I'm making settings page like this one on AliExpress app. If you click currency, it opens new modal page, where you select your preferred currency and when you click back, currency (EUR, USD, GBP,...) is updated and shown on the right side. Same for Language, Ship to and so on. So
My question is, should every page have its own viewmodel or should I use one "big" viewmodel, let's say SettingsViewModel which I use for all settings?

I'm working without any framework. What is the best way to do it?

Tagged:

Best Answer

Answers

  • JoeMankeJoeManke USMember ✭✭✭✭✭

    I generally go with a one-to-one VM-to-Page ratio, but for something like this where it's just viewing vs editing the same data I think sharing the ViewModel is fine.

  • rozman50rozman50 Member ✭✭

    @JoeManke How can I achieve this? Share one viewmodel with multiple views? Now I'm creating new instance of SettingsVM every time I open page

  • JoeMankeJoeManke USMember ✭✭✭✭✭

    I'm probably going to unleash the wrath of Clint for saying this, but I would pass the ViewModel from the main settings page to the edit page as a constructor argument.

  • NMackayNMackay GBInsider, University mod

    @JoeManke said:
    I'm probably going to unleash the wrath of Clint for saying this, but I would pass the ViewModel from the main settings page to the edit page as a constructor argument.

    Offfft, not only Clint's wrath :D

Sign In or Register to comment.