Objective-C面向對象的響應式框架:Objective-Chain

jopen 10年前發布 | 15K 次閱讀 Objective-C開發 Objective-Chain

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.baiduhome.net/lib/view/home/1416016397883

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!