Last active
March 20, 2018 05:41
-
-
Save kmmraj/7ec50bd9159e9473d7680b25c047e1b9 to your computer and use it in GitHub Desktop.
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
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