CleanArchitectureRxSwift
CleanArchitectureRxSwift copied to clipboard
Issues with the current ViewModel implementation.
Hi Serg,
First of all, I want to thank you for the great explanation about CleanArchitecture, but I am a bit concerned about the way the ViewModel is created. Based on this approach, if a change is made in the Input, the transform function will be called and all the outputs will be recreated again. This is not necessarily right.
extension ViewModel: ViewModelType {
struct Input {
...
}
struct Output {
...
}
func transform(input: Input) -> Output {
...
return Output(output: someOutput)
}
}
What if we create the ViewModel like this, in a protocol oriented way:
protocol ViewModelInput {
...
}
protocol ViewModelOutput {
...
}
protocol ViewModelType {
var input: ViewModelInput { get }
var output: ViewModelOutput { get }
}
extension ViewModel: ViewModelInput, ViewModelOutput, ViewModelType {
var input: ViewModelInput { return self }
var output: ViewModelOutput { return self }
...
}
The ViewModel is easier to be tested and the outputs aren't recreated for every change in Input.
What do you think?
@sergdort Anything?
Hi @jdisho
Not sure what do you mean by:
if a change is made in the Input, the transform function will be called and all the outputs will be recreated again.
I believe that in the example app Input
is just a struct
that contains user input observables