rootstrap / ios-base

Boilerplate for new iOS projects using Swift 5. Provides a handful of functionalities.
https://rootstrap.com/
MIT License
259 stars 63 forks source link

MVVM approach proposal #94

Closed germanStabile closed 5 years ago

germanStabile commented 5 years ago

refactor HomeViewController/ViewModel to a different MVVM approach, in which the view model updates its state describing the work being done and the view controller is responsible to update its views according to the view model state.

This patterns allows a lighter view controller and gives more responsibility to the view model making it more than an intermediate between the view controller and the service layer.

toptierlabs commented 5 years ago
1 Error
:no_entry_sign: PR is classed as Work in Progress. Do NOT merge

Generated by :no_entry_sign: Danger

glm4 commented 5 years ago

I can't see anything wrong with this implementation, and I really like it.

Just want to ask you, @germanStabile, what do you recommend for a more complex scenario, i.e: the view controller needs other attributes and UI changes to do. I would say that, in that case, we may want to make the delegate method smarter, where it passes the attribute changed and the old/new value to the delegate(like a KVO does). That way we don't end up with really long enums and endless states to manage in the view controller.

In the worst case scenario, If a considerably big amount of properties or states is needed, I would consider a binding solution/library(RX).

WDY'allT? 😃

germanStabile commented 5 years ago

Right, @glm4. As you say we can either add more methods to the delegate or add parameters (like old and new value) to didUpdateState according to the complexity of the view controller we are implementing.

There may also be cases in which you'd want to add different state properties to avoid blocking user interaction for small UI updates.

In my personal experience binding libraries tend to add extra (and sometimes unneeded) complexity but it's also valid solution for some cases.

glm4 commented 5 years ago

@germanStabile Agree, maybe with following examples we can see it better.

That is my point, let's no forget that if things get more complicated, we can jump into binding solutions. Just to have them in mind and not to get too attached to simple communications ways between VMs and VCs.

Very nice job!

CamilaMoscatelli commented 5 years ago

I really like this approach, nice work!