We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi, What do you think about the introduction of BindableType protocol?
protocol BindableType { associatedtype ViewModel: ViewModelType var viewModel: ViewModel { get } func bindInput() -> ViewModel.Input func bind(output: ViewModel.Output) } extension BindableType { func bindViewModel() { let input = bindInput() let output = viewModel.transform(input: input) bind(output: output) } }
Example:
import RxSwift import RxCocoa class ViewModel: ViewModelType { struct Input { let trigger: Driver<Void> } struct Output { let value: Driver<Void> } func transform(input: Input) -> Output { return Output(value: input.trigger) } } class ViewController: UIViewController, BindableType { let viewModel: ViewModel private let disposeBag = DisposeBag() init(viewModel: ViewModel) { self.viewModel = viewModel super.init(nibName: nil, bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func viewDidLoad() { super.viewDidLoad() bindViewModel() } func bindInput() -> ViewModel.Input { return ViewModel.Input(trigger: .just(())) } func bind(output: ViewModel.Output) { output.value .drive() .disposed(by: disposeBag) } }
The text was updated successfully, but these errors were encountered:
This is interesting approach 👍
My concern tho is that it makes ViewModel public in the ViewController right?
ViewModel
ViewController
Sorry, something went wrong.
Great approach!
No branches or pull requests
Hi,
What do you think about the introduction of BindableType protocol?
Example:
The text was updated successfully, but these errors were encountered: