Skip to content

Instantly share code, notes, and snippets.

@ininmm
Created September 18, 2019 01:44
Show Gist options
  • Save ininmm/c7ad9a8aa41b244ae76e1dd093804d81 to your computer and use it in GitHub Desktop.
Save ininmm/c7ad9a8aa41b244ae76e1dd093804d81 to your computer and use it in GitHub Desktop.
使用 Lambda 的 ViewModel
fun getTokenAsync(action: (Token) -> Unit) {
......
}
fun verifyAsync(
token: Token,
userName: String,
action: (Boolean) -> Unit
) {
......
}
fun requestAndSaveUserDataAsync(
userName: String,
result: (Result) -> Unit
) {
......
}
......
fun login(userName: String) {
getTokenAsync { token ->
verifyAsync(token, userName) { verifyResult ->
requestAndSaveUserDataAsync(userName) { result ->
showLoginSuccess("Success")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment