timothytooth / dvice-swiftui-arch

0 stars 0 forks source link

Some thoughts #1

Open mareeeeeeek opened 3 years ago

mareeeeeeek commented 3 years ago

Could this demo be modified to show how the Navigation works? I'm curios how it really works but it looks really interesting.

I think SwiftUI works really well with a reactive data binding approach. Looking at the ViewModel, it seems like they are just plain old swift structs containing simple non-bindable values. In the case of nested ViewModels, for example, repeating lists (table view cells), would cells bind to the view model and listen in on any updates of the individual values or would the full cell need to be reloaded when a value changes?

What I mean is should the ViewModel change from:


 struct ExampleViewModel {
     var isAlertShowing: Bool = false
     var errorString: String = ""
 }

to this:

 final class ExampleViewModel: ObservableObject {
     @Published var isAlertShowing: Bool = false
     @Published var errorString: String = ""
 }

or maybe it could also be a protocol. I sort of like to define ViewModels as protocols but then again my top level ViewModel is basically the Director. I do think there are some advantages to explicitly call out the top-level ViewModel as a separate component with well defined responsibilities.

If the ViewModels change from simple structs to something more complex, it does bring in the option to remove the Translator altogether and move that logic in to the ViewModel. This is still unit testable but it simplifies the structure a bit. It also gets rid of the need to create new view models upon a change in the application state.

Another question that I have is if the Director is really needed. If the director is removed then we end up with a flavor of .... (drumroll) MVVM+Coordinator.

mareeeeeeek commented 3 years ago

Another thing to think about is how will this architecture scale when the application gets really large. Is there a pattern that can be created into DVICE to facilitate making decoupled feature frameworks and the routing between them without tightly coupling all the feature flows together. While this may seem unnecessary right now but as the application gets larger, this works gets much harder and time consuming.