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

Generate extension functions for classes which have public functions accepting sealed classes instances as parameters #83

Open
Pschsch opened this issue Jun 29, 2023 · 0 comments

Comments

@Pschsch
Copy link

Pschsch commented Jun 29, 2023

Example:
Now:

class AwesomeViewModel : ViewModel() {
   sealed class Parameter {
       object ObjectParameter : Parameter()
       data class ClassParameter(val param : Int): Parameter()
   } 
   ...
   fun handleParameter(parameter : Parameter) {
       when (parameter) {
   ...
}

class Controller : UIViewController {
    let viewModel : AwesomeViewModel
    ...
    
    private func sendParameters() {
         viewModel.handleParameter(parameter: AwesomeViewModel.ParameterObjectParameter.shared) /* uuugh */
         viewModel.handleParameter(parameter: AwesomeViewModel.ParameterClassParameter(param : Int32(0))) /* uuugh */
    }
}

Wish

class Controller : UIViewController {
    let viewModel : AwesomeViewModel
    ...
    
    private func sendParameters() {
         viewModel.handleParameter(parameter: .objectParameter) /* yeaaah */
         viewModel.handleParameter(parameter: .classParameter(param: 0)) /* yeaaah */
    }
}

What extension will be generated for this

import ${shared module name}

extension AwesomeViewModel {
    func handleParameter(parameterKs : AwesomeViewModelParameterKs) {
        self.handleParameter(parameter: parameterKs.sealed)
    }
}

The same logic could be applied for constructors/initializers

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

1 participant