The validateUsername will finally called the following method:
func usernameAvailable(username: String) -> Observable<Bool> {
// this is ofc just mock, but good enough
print("message2")
let URL = NSURL(string: "https://github.com/\(username.URLEscaped)")!
let request = NSURLRequest(URL: URL)
return self.URLSession.rx_response(request)
.map { (maybeData, response) in
print("message3")
return response.statusCode == 404
}
.catchErrorJustReturn(false)
}
The input.username is a textfield.rx_text, when I input the character in the textfield quickly before the network request returned:
message1 and message2 showed as many times as the characters I input, but message3 only showed once.
If I changed the flatMapLatest to flatMap, the number of times that message3 showed is equal to the characters' count.
How did the flatMapLatest work?
I searched the document and read some articles online, all of those explanation of flatMapLatest is like following:
let a = Variable(XXX)
a.asObservable.flatMapLatest(...)
When changed a.value to another value, the Variable(XXX) will not influence the subscriber of a.
But the question above is input.name isn't changed! It is always the textfield.rx_text.
In the file GithubSignupViewModel1.swift, the definition of validatedUsername is:
The validateUsername will finally called the following method:
The
input.username
is atextfield.rx_text
, when I input the character in the textfield quickly before the network request returned: message1 and message2 showed as many times as the characters I input, but message3 only showed once. If I changed the flatMapLatest to flatMap, the number of times that message3 showed is equal to the characters' count. How did the flatMapLatest work?I searched the document and read some articles online, all of those explanation of flatMapLatest is like following:
When changed
a.value
to another value, theVariable(XXX)
will not influence the subscriber of a. But the question above isinput.name
isn't changed! It is always thetextfield.rx_text
.