RACSignal: Why use rac_textSignal to “defer” to bring RACSignal back to itself?

rac_textSignal-Implementation uses "defer" to return RACSignal to "self". What is the reason for this?

This is the implementation:

- (RACSignal *)rac_textSignal {
    @weakify(self);
    return [[[[[RACSignal
        defer:^{
            @strongify(self);
            return [RACSignal return:self];
        }]
        concat:[self rac_signalForControlEvents:UIControlEventEditingChanged]]
        map:^(UITextField *x) {
            return x.text;
        }]
        takeUntil:self.rac_willDeallocSignal]
        setNameWithFormat:@"%@ -rac_textSignal", [self rac_description]];
}
+4
source share
3 answers

Both the delayed signal and the concatenated signal are sent UITextField(efficiently self).

A delayed signal causes the returned signal to send the current saved text when subscribing, since it [self rac_signalForControlEvents:UIControlEventEditingChanged]sends only changes.

+3
source

If you must refuse to defer and implement it, like:

- (RACSignal *)rac_textSignal {
    @weakify(self);
    return [[[[[RACSignal return:self]
            concat:[self rac_signalForControlEvents:UIControlEventEditingChanged]]
            map:^(UITextField *x) {
                return x.text;
            }]
            takeUntil:self.rac_willDeallocSignal]
            setNameWithFormat:@"%@ -rac_textSignal", [self rac_description]];
 }

RAC, self, , UITextField.

+1

I think deferment is just to prevent the save cycle

0
source

All Articles