Generate extension functions for classes which have public functions accepting sealed classes instances as parameters
Opened this issue · 0 comments
Pschsch commented
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