Created
November 26, 2018 13:48
-
-
Save Sajjon/5058d110b532a0ab30633c7544c9b6b9 to your computer and use it in GitHub Desktop.
Medium article: SLC part 1 - BaseViewModel
This file contains 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
import RxSwift | |
import RxCocoa | |
class BaseViewModel<NavigationStep, FromView, Output>: ViewModelType { | |
let bag = DisposeBag() | |
// Small type wrapping a RxSwift PublishSubject, that we notify about navigation, passing | |
// a contextual `NavigationStep` which typically is an enum, modelling all possible | |
// outgoing navigation steps we can take from this scene. | |
let navigator = Stepper<NavigationStep>() | |
// MARK: - Methods to Override | |
func transform(input: Input) -> Output { abstract } | |
} | |
extension BaseViewModel { | |
struct Input: InputType { | |
let fromController: ControllerInput | |
let fromView: FromView | |
init(fromView: FromView, fromController: ControllerInput) { | |
self.fromView = fromView | |
self.fromController = fromController | |
} | |
} | |
} | |
struct ControllerInput { | |
let viewDidLoad: Driver<Void> | |
// `Bool` representing argument `animated` | |
let viewWillAppear: Driver<Bool> | |
let viewDidAppear: Driver<Bool> | |
let leftBarButtonTrigger: Driver<Void> | |
let rightBarButtonTrigger: Driver<Void> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment