0

I couldn't find much documentation about RAC then operator. What is the purpose it serves. When should I use. it? Can someone explain in below context?

[[[[self requestAccessToTwitterSignal]
  then:^RACSignal *{
    @strongify(self)
    return self.searchText.rac_textSignal;
  }]
  filter:^BOOL(NSString *text) {
    @strongify(self)
    return [self isValidSearchText:text];
  }]
  subscribeNext:^(id x) {
    NSLog(@"%@", x);
  } error:^(NSError *error) {
    NSLog(@"An error occurred: %@", error);
  }];

2 Answers 2

2

The code documentation provide a sound explanation.

/// Ignores all `next`s from the receiver, waits for the receiver to complete,
/// then subscribes to a new signal.
///
/// block - A block which will create or obtain a new signal to subscribe to,
///         executed only after the receiver completes. This block must not be
///         nil, and it must not return a nil signal.
///
/// Returns a signal which will pass through the events of the signal created in
/// `block`. If the receiver errors out, the returned signal will error as well.

So in your context. it waits until requestAccessToTwitterSignal complete. Ignores any event after that. And then subscribes to the new signal. Which is self.searchText.rac_textSignal. The filter applies to the new signal.

2

It essentially just makes the signal you apply it to work as a delay, it won't send next events until the original signal completes, at which point it'll switch to the signal you supplied with then:.

requestAccessToTwitterSignal will do something stateful and set a twitter token of some kind, so we use then: to wait until it's done and return a new signal that we want to get next events from.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.