0

我找不到太多关于 RACthen操作员的文档。它的目的是什么。我应该什么时候使用。它?有人可以在下面的上下文中解释吗?

[[[[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);
  }];
4

2 回答 2

2

它本质上只是使您应用它的信号作为延迟工作,在原始信号完成之前它不会发送next事件,此时它将切换到您提供的信号then:

requestAccessToTwitterSignal将做一些有状态的事情并设置某种类型的 twitter 令牌,所以我们then:习惯于等到它完成并返回一个我们想要从中获取next事件的新信号。

于 2016-03-11T05:39:44.237 回答
2

代码文档提供了合理的解释。

/// 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.

所以在你的上下文中。它一直等到 requestAccessToTwitterSignal 完成。之后忽略任何事件。并then订阅新信号。这是self.searchText.rac_textSignalfilter应用于新信号。

于 2016-03-11T05:41:31.723 回答