Open PaMicht opened 3 years ago
I think the best solution is to allow mutable members in a ViewModel
but we have to restrict all view models to be of type struct
because it wouldn't work with classes.
I also like the 2 solution. Since structs are value types it should be no problem to have mutable properties.
I think the best solution is to allow mutable members in a
ViewModel
but we have to restrict all view models to be of typestruct
because it wouldn't work with classes.
One thing I just noticed: Does this mean that the update mechanism of StatefulViewController
is triggered each time the ViewModel
changes? Take this code for example:
self.model.isLoading = true
self.model.isRefreshing = true
self.model.title = 'Some title'
Would this update the view 3 times? If so, then tis could be a performance overhead.
I was wondering if there is no cleaner way of updating immutable
ViewModel
properties than doing that inside aStatefulViewController
:Solution 1
A suggestion would be to have an extension for
StatefulViewController
containing this:Extension in action:
Solution 2
Another approach could be to allow
var
properties in theViewModel
. Setting avar
property would automatically trigger the update mechanism of theStatefulViewController
. Code example: