Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with the current ViewModel implementation. #40

Open
jdisho opened this issue Feb 6, 2018 · 2 comments
Open

Issues with the current ViewModel implementation. #40

jdisho opened this issue Feb 6, 2018 · 2 comments

Comments

@jdisho
Copy link

jdisho commented Feb 6, 2018

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?

@jdisho
Copy link
Author

jdisho commented Feb 21, 2018

@sergdort Anything?

@sergdort
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants