Reputation: 988
I am trying to understand this piece of code and why it returns a signal of signals.
[[[self.signInButton
rac_signalForControlEvents:UIControlEventTouchUpInside]
map:^id(id x) {
return [self signInSignal];
}]
subscribeNext:^(id x) {
NSLog(@"Sign in result: %@", x);
}];
From what I understand the UIControlEventTouchupInside returns a next signal which contains the UIButton when unwrapped in the map function.
So from this, is it safe to conclude that when I perform the map, it expects that the object returned is an object (which happens to be a signal) and it double wraps the signal into a signal. That is reactive cocoa usually expects the type to be a object type and wrap's it into a signal ?
Or
Am I missing something here, and my understanding of Map is not as follows, It transforms the input value, and produces an output value, (independent of the input value sometimes)
Thanks I am new to this any advice would be nice!
Another related question,
Lets just say that uicontrol event touch up inside sends and error event, would it be caught by the subscribe next error ?
Upvotes: 1
Views: 759
Reputation: 6489
The code looks incorrect. You are correct in understanding that the code takes the signal of button taps and maps it to a signal of "sign-in signals". Yes, a signal of signals. While a signal of signals is common and very useful, it will do nothing without the use of one of these three operators: flatten
, concat
or switchToLatest
. In the given code, signInSignal
will never be triggered because none of these operators are used.
If you switch map:
to flattenMap:
, the sign-in signal will be properly started.
[[[self.signInButton
rac_signalForControlEvents:UIControlEventTouchUpInside]
flattenMap:^id(id x) {
return [self signInSignal];
}]
subscribeNext:^(id x) {
NSLog(@"Sign in result: %@", x);
}];
Upvotes: 4