Objective-C面向对象的响应式框架:Objective-Chain

jopen 9年前

Objective-Chain是一个面向对象的响应式框架,作者表示该框架吸收了 ReactiveCocoa 的思想,并且想做得更面向对象一些。

主要的组件

.核心理念是非常简单的:生产者发送值和消费者接受他们。生产者和消费者都是抽象的,所以真正的功能是由它们的具体实现提供。

Producers

  • Timer – Periodically sends time intervals to Consumers until stopped.
  • Property – Observes KVO notifications of given object and key-path and sends latest values to Consumers. It's one of the Core features.
  • Notificator – Observes NSNotifications with given name and sends them to Consumers.
  • Target – Receiver of target-action callbacks that sends the sender to Consumers.
  • Command – Generic Producer to be used manually by invoking its methods.
  • Hub – Special Producer, that takes multiple other Producers and forwards their values. There are currently three kinds fof Hub: merging, combining and depending. More on those later.

  • In addition, you can easily subclass Producer with custom implementation. If there are other sources of events/values that should be implemented, feel free to suggest it.

Consumers

  • Property – Yes, the same Property as the Producer above, but this time it set received values using KVC. Setting usually triggers KVO event, that is immediately produced. It's one of the Core features.
  • Invoker – Invokes regular invocations optionally replacing the arguments with received values. Don't worry, it has never been easier to create and use NSInvocations! It's one of the Core features.
  • Subscriber – Most versatile Consumer, that can be customized using blocks. Allows you to easily create ad-hod implementations of consumers, if there is no better alternative (and trust me, there usually is).
  • Switch – Similar to switch or if-else control statements, Switch takes multiple Consumers with one Predicate for each. Once it receives value, it invokes all sub-consumers whose predicates evaluate to YES.

  • There are some more provided Consumers, but they usually only uses Subscriber to perform their task. If there are other special cases, that need custom subclass, suggest them.



 

项目主页:http://www.open-open.com/lib/view/home/1416016397883