Skip to content

Instantly share code, notes, and snippets.

@kmmraj
Last active March 20, 2018 05:41
Show Gist options
  • Save kmmraj/7ec50bd9159e9473d7680b25c047e1b9 to your computer and use it in GitHub Desktop.
Save kmmraj/7ec50bd9159e9473d7680b25c047e1b9 to your computer and use it in GitHub Desktop.
typealias GHLoginObservableType = Pair<LoginResultAction,Store<StateType>>
fun getGHLoginSingleSubscriber(): SingleObserver<GHLoginObservableType> {
return object : SingleObserver<Pair<LoginResultAction,Store<StateType>>> {
override fun onSubscribe(d: Disposable) {}
override fun onSuccess(value: GHLoginObservableType) {
val (loginResultAction,store) = value
if (loginResultAction.loginStatus == LoggedInState.notLoggedIn) {
store.dispatch(LoginFailedAction(userName = loginResultAction.userName,
message = loginResultAction.message as String))
} else {
store.dispatch(LoginCompletedAction(loginResultAction))
store.dispatch(LoggedInDataSaveAction(userName = loginResultAction.userName,
token = loginResultAction.token as String, loginStatus = LoggedInState.loggedIn))
}
}
override fun onError(e: Throwable) {
mainStore.dispatch(LoginFailedAction(userName = "",
message = "Internal Error"))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment