What is RACSignal?

A signal takes all those async methods for controlling the flow of information through your app (delegates, callback blocks, notifications, KVO, target/action event observers, etc) and unifies them under one interface. This just flat out makes sense. Not only that, it gives you the ability to transform/split/combine/filter that information easily as it flows through your application.

  • Signal is an object that sends out a stream of values.
  • A signal will only send out information if it has a subscriber listening to it.
  • It will send that subscriber 0 or more “next” events containing the value, followed by either a “complete” event or an “error” event.

Where do signals get the values they are sending along?

  • From createSignal: 当创建信号的时候, 可以指定, 这个信号被订阅之后会执行一些动作, 这个动作可以向外sending value

  • From RACObserve(): 也就相当于创建了信号, 此时执行的动作是给被观察的对象增加KVO或是其他, 每当观察的object发生改变的时候向外sending value

  • From rac_signalForControlEvents, rac_textSignal, rac_signalForSelector, rac_buttonClickedSignal: 此时也是相当于创建信号, 只不过此时观测对象是某个事件, 当事件触发的时候向外sending value

What is a subscriber?

A subscriber is the bit of code that is waiting for the signal to send along its values so it can do something with them. (It can also act on the “complete” and “error” events too).

Expensive operation:

Every time a new value is sent through that chain, it is actually sent once per subscriber.

results matching ""

    No results matching ""