Skip to content

Instantly share code, notes, and snippets.

@KonstantinBerkow
Created January 29, 2018 18:54
Show Gist options
  • Save KonstantinBerkow/7366ca6a6fbd99de4ec91fd9a0928f7e to your computer and use it in GitHub Desktop.
Save KonstantinBerkow/7366ca6a6fbd99de4ec91fd9a0928f7e to your computer and use it in GitHub Desktop.
Presenter for login
@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