Reactivecocoa-publish、multicast、replay、replayLast

//-replay 总是收取最后的内容,而并不执行signal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  __block int num = 0;
  RACSignal *signal = [[RACSignal createSignal:^RACDisposable *(id  subscriber) {
      num++;
      NSLog(@"Increment num to: %i",num);
      [subscriber sendNext:@(num)];
      return nil;
  }] replay];
 
  NSLog"Start subscriptions");
 
  // Subscriber 1 (S1)
  [signal subscribeNext:^id x{
      NSLog"S1: %@",x);
  ];
 
  // Subscriber 2 (S2)
  "S2: %@",10)">// Subscriber 3 (S3)
  "S3: %@",0)">];
Incrementnumto:1
Startsubscriptions
S1:1
S2:1
S3:1
-replay 总是取出第一订阅者取到的 所有结果
-replayLast 总是取出第一个订阅者取到的 最后一个结果
-replayLazily有点说不上来
replayLazily does not subscribe to the signal immediately – it lazily waits until there is a “real” subscriber. But replay subscribes immediately. So as you point out,with replayLazily the “A” value would not be sent to subscribers of the signal because it was sent before there was anything listening.

RACMulticastConnection public connect
当一个信号被订阅了几次,那么它将会执行几次,见下方代码:
RACSignal *signal1 = [ RACSignal defer :^ *{
NSLog ( @"print signal1" );
return [ RACSignal : @"hello" ];
}];

[signal1
subscribeNext :^( id x) {
@"first %@" ,x);
}];

[signal1
@"second %@"
}];
2015-06-05 14:35:38.149 DemoCategorizer[15252:2226982] print signal1
2015-06-05 14:35:38.149 DemoCategorizer[15252:2226982] first hello
2015-06-05 14:35:38.149 DemoCategorizer[15252:2226982] print signal1
2015-06-05 14:35:38.149 DemoCategorizer[15252:2226982] second hello
那么,我打算某个网络操作只做一次,然后多个订阅者都可以收到消息,怎么做?
@"signal1" ];
}];

RACMulticastConnection *connection = [signal1 publish ];
[connection.
signal @"first next value = %@" @"second next value = %@"
[connection connect];
2015-06-05 14:38:48.528 DemoCategorizer[15848:2239991] print signal1
2015-06-05 14:38:48.528 DemoCategorizer[15848:2239991] first next value = signal1
2015-06-05 14:38:48.528 DemoCategorizer[15848:2239991] second next value = signal1
signal1只是被执行了一次,神奇不? 详见 http://www.jianshu.com/p/a0a821a2480f

相关文章

一、前言 在组件方面react和Vue一样的,核心思想玩的就是组件...
前言: 前段时间学习完react后,刚好就接到公司一个react项目...
前言: 最近收到组长通知我们项目组后面新开的项目准备统一技...
react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...