-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
I was wondering if there is no cleaner way of updating immutable ViewModel properties than doing that inside a StatefulViewController:
var actualModel = self.model
actualModel.isLoading = true
self.model = actualModelSolution 1
A suggestion would be to have an extension for StatefulViewController containing this:
import JamitFoundation
extension StatefulViewController {
func updateModel(modifier: (inout Model) -> Void) {
var actualModel = model
modifier(&actualModel)
self.model = actualModel
}
}Extension in action:
viewController.updateModel { $0.isLoading = true }Solution 2
Another approach could be to allow var properties in the ViewModel. Setting a var property would automatically trigger the update mechanism of the StatefulViewController .
Code example:
self.model.isLoading = true // isLoading is a varMetadata
Metadata
Assignees
Labels
No labels