Created
January 29, 2018 18:54
-
-
Save KonstantinBerkow/7366ca6a6fbd99de4ec91fd9a0928f7e to your computer and use it in GitHub Desktop.
Presenter for login
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
@AuthScope | |
class LoginPresenter | |
@Inject constructor(private val interactor: LoginInteractor) : BasePresenter<LoginState, LoginEvent> { | |
private val resultsSubj = PublishSubject.create<LoginResult>().toSerialized() | |
private val stateObs: Observable<LoginState> | |
init { | |
val initial = LoginState() | |
stateObs = resultsSubj | |
.scan(initial) { old, result -> result.alterState(old) } | |
.replay(1) | |
.autoConnect() | |
} | |
override fun state(): Observable<LoginState> { | |
return this.stateObs | |
} | |
override fun attachEvents(events: Observable<LoginEvent>) { | |
events.ofType(Submit::class.java) | |
.flatMap { event -> interactor.login(event.email, event.password) } | |
.subscribe(resultsSubj) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment