Last active
November 26, 2018 14:31
-
-
Save Sajjon/19096243ff15ce017ca802043f0c6a5e to your computer and use it in GitHub Desktop.
Medium article: SLC part 1 - ViewModel (simple)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The cases should be named as if they were prefixed with the words | |
| // "user intends to" or "user did" | |
| enum AuthenticateNavigationStep { | |
| case signIn | |
| case signUp | |
| } | |
| final class AuthenticateViewModel: BaseViewModel< | |
| AuthenticateNavigationStep, | |
| AuthenticateViewModel.InputFromView, | |
| AuthenticateViewModel.Output | |
| > { | |
| // MARK: - Overriding methods | |
| override func transform(input: Input) -> Output { | |
| func userIntends(to intention: AuthenticateNavigationStep) { | |
| navigator.navigate(to: intention) | |
| } | |
| [ | |
| input.fromView.signUpTrigger | |
| .do(onNext: { userIntends(to: .signUp) }) | |
| .drive(), | |
| input.fromView.signInTrigger | |
| .do(onNext: { userIntends(to: .signIn) }) | |
| .drive() | |
| ].forEach { $0.disposed(by: bag) } | |
| return Output() | |
| } | |
| } | |
| extension AuthenticateViewModel { | |
| struct InputFromView { | |
| let signUpTrigger: Driver<Void> | |
| let signInTrigger: Driver<Void> | |
| } | |
| struct Output {} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment