RAC-框架概览

流(RACStream):一个流表示多个对象值组成的序列,对象值可以是当前已有的,也可以是未来会出现的,但是必须先后按顺序依次被检索。

信号(RACSignal):信号是推送型的流,信号可以通过订阅来传递事件给订阅者,主要有三类事件:next,error,complete。next可以携带一个正常的值对象,error表示发生异常并传递NSError对象,completed表示成功结束。信号的生命周期中可以发出多个next事件,然后跟着一个error事件或一个complete事件。

订阅者(RACSubscriber):当对信号使用subscribeNext:error:completed等订阅接口时,RAC会隐式的生成一个订阅者。该订阅者持有该信号,直到信号发生了error或complete事件,订阅者会被自动清理掉。

主题(RACSubject): 主题是一种灵活的信号,可以被随时用来发送next事件,不用考虑是否有订阅者存在

Commands

command, represented by the RACCommand class, creates and subscribes to a signal in response to some action. This makes it easy to perform side-effecting work as the user interacts with the app.

Usually the action triggering a command is UI-driven, like when a button is clicked. Commands can also be automatically disabled based on a signal, and this disabled state can be represented in a UI by disabling any controls associated with the command.

On OS X, RAC adds a rac_command property to NSButton for setting up these behaviors automatically.

Connections

connection, represented by the RACMulticastConnection class, is a subscription that is shared between any number of subscribers.

Signals are cold by default, meaning that they start doing work each time a new subscription is added. This behavior is usually desirable, because it means that data will be freshly recalculated for each subscriber, but it can be problematic if the signal has side effects or the work is expensive (for example, sending a network request).

A connection is created through the -publish or -multicast: methods on RACSignal, and ensures that only one underlying subscription is created, no matter how many times the connection is subscribed to. Once connected, the connection‘s signal is said to be hot, and the underlying subscription will remain active until all subscriptions to the connection are disposed.

Sequences

sequence, represented by the RACSequence class, is a pull-driven stream.

Sequences are a kind of collection, similar in purpose to NSArray. Unlike an array, the values in a sequence are evaluated lazily (i.e., only when they are needed) by default, potentially improving performance if only part of a sequence is used. Just like Cocoa collections, sequences cannot contain nil.

Sequences are similar to Clojure‘s sequences (lazy-seq in particular), or the List type in Haskell.

RAC adds a -rac_sequence method to most of Cocoa‘s collection classes, allowing them to be used as RACSequences instead.

Disposables

The RACDisposable class is used for cancellation and resource cleanup.

Disposables are most commonly used to unsubscribe from a signal. When a subscription is disposed, the corresponding subscriber will not receive any further events from the signal. Additionally, any work associated with the subscription (background processing, network requests, etc.) will be cancelled, since the results are no longer needed.

For more information about cancellation, see the RAC Design Guidelines.

Schedulers

scheduler, represented by the RACScheduler class, is a serial execution queue for signals to perform work or deliver their results upon.

Schedulers are similar to Grand Central Dispatch queues, but schedulers support cancellation (via disposables), and always execute serially. With the exception of the +immediateScheduler, schedulers do not offer synchronous execution. This helps avoid deadlocks, and encourages the use of signal operators instead of blocking work.

RACScheduler is also somewhat similar to NSOperationQueue, but schedulers do not allow tasks to be reordered or depend on one another.

Value types

RAC offers a few miscellaneous classes for conveniently representing values in a stream:

  • RACTuple is a small, constant-sized collection that can contain nil (represented by RACTupleNil). It is generally used to represent the combined values of multiple streams.
  • RACUnit is a singleton "empty" value. It is used as a value in a stream for those times when more meaningful data doesn‘t exist.
  • RACEvent represents any signal event as a single value. It is primarily used by the -materialize method ofRACSignal.
时间: 2024-10-27 18:27:04

RAC-框架概览的相关文章

IOS框架概览

iOS是运行在iPhone.iPod Touch或iPad上的操作系统,之前叫做iPhone OS,iOS与Mac OS X有共同的基础架构和底层技术.但iOS是根据移动设备的特点而设计的,所以和Mac OS X系统略有区别,比如对多点触摸和加速感应器的支持. 下面来看看iOS框架简介: iOS 的系统架构分为四个层次:核心操作系统层(Core OS layer).核心服务层(Core Services layer).媒体层(Media layer)和可触摸层(Cocoa Touch layer

HsqlDB源码学习——基本框架概览

Database: Database is the root class for HSQL Database Engine database.It holds the data structures that form an HSQLDB database instance. 整个体系结构大致如上图!接下来便一个一个学习,多么蛋疼的过程! HsqlDB源码学习--基本框架概览

开源跨平台数据格式化框架概览

说到数据格式化框架,就不得不提到 Google 的 Protocol Buffers,Facebook 的 Thrift,还有 Apache Hadoop 推出的 Avro.Microsoft 最近开源的 Bond 也是一种用于数据格式化的可扩展框架,其适用的应用场景包括服务间通信.大数据存储和处理等. 为什么会有这么多关于数据格式处理的框架?它们都在解决什么问题呢?我们先来观察一下典型的服务间通信的结构. 通常,在设计服务间通信时,我们所要面对的基本问题有: 如何传输数据? 使用什么协议通信?

XML解析框架概览

iOS SDK 提供了两个XML框架: 1.NSXML,基于Objective-C语言的SAX解析框架,他是iOS SDK默认的XML解析框架,他不支持DOM模式. 2.libxml2,基于C语言的第三方提供的sax解析框架,他被苹果整合在iOS SDK中,它支持sax和dom模式. 解析XML的其它第三方框架: 1.TBXML,是轻量级的DOM解析模式 2.TouchXML,基于DOM模式解析库,与TBXML类似,只能读取XML不能写入XML文档. 3.KissXML,基于DOM模式解析库,它

响应式编程框架ReactiveCocoa学习——框架概览

这篇博客将会继续翻译RAC的官方文档Framework Overview. 主要是对RAC这和框架进行概览的介绍和学习.同时也可以参考我前面的两篇翻译<响应式编程框架ReactiveCocoa学习--基本操作符><响应式编程框架ReactiveCocoa介绍与入门>.其中ReactiveCocoa的Github官方地址为 https://github.com/ReactiveCocoa/ReactiveCocoa . 这篇文档包括了RAC中的对不同组件的高层描述,并解释如何进行结合

Java web技术框架概览

1.基础框架 1.1 后台基础框架 分布式:dubbox 统一配置:zookeeper 消息:kafka 服务化:spring  spring boot 微服务化框架 spring mvc springframework 持久层:mybatis.hibernate.jedis 项目构建:maven 单元测试:junit.testNG 可视化测试:soapUI.jmeter 2. 前端框架 原型:axure html:html.jsp.thymeleaf.Velocity.freemarker c

常用Cocoa框架概览

Cocoa不是一种编程语言(它可以运行多种编程语言),它也不是一个开发工具(通过命令行我们仍然可以开发Cocoa程序),它是创建Mac OS X和IOS程序的原生面向对象API,为这两者应用提供了编程环境. 我们通常称为"Cocoa框架",事实上Cocoa本身是一个框架的集合,它包含了众多子框架,其中最重要的要数"Foundation"和"UIKit".前者是框架的基础,和界面无关,其中包含了大量常用的API:后者是基础的UI类库,以后我们在IO

JDK源码分析(7)之 Reference 框架概览

对于Reference类大家可能会比较陌生,平时用的也比较少,对他的印象可能仅停在面试的时候查看引用相关的知识点:但在仔细查看源码后发现Reference还是非常实用的,平时我们使用的类都是强引用的,它的回收完全依赖于 GC:但是对于有些类我们想要自己控制的时候就比较麻烦,比如我想在内存还足够的时候就保留,不够的时候就回收,这时使用Reference就能够十分灵活的控制类的存亡了. 一.类定义 /** * Abstract base class for reference objects. Th

Volley框架源码分析

Volley框架分析Github链接 Volley框架分析 Volley源码解析 为了学习Volley的网络框架,我在AS中将Volley代码重新撸了一遍,感觉这种照抄代码也是一种挺好的学习方式.再分析Volley源码之前,我们先考虑一下,如果我们自己要设计一个网络请求框架,需要实现哪些事情,有哪些注意事项? 我的总结如下: 需要抽象出request请求类(包括url, params, method等),抽象出request请求类之后,我们可以对其继承从而实现丰富的扩展功能. 需要抽象出resp

WebKit框架 浅析

摘要 WebKit是iOS8之后引入的专门负责处理网页视图的框架,其比UIWebView更加强大,性能也更优. iOS中WebKit框架应用与解析 一.引言 在iOS8之前,在应用中嵌入网页通常需要使用UIWebView这样一个类,这个类通过URL或者HTML文件来加载网页视图,功能十分有限,只能作为辅助嵌入原生应用程序中.虽然UIWebView也可以做原生与JavaScript交互的相关处理,然而也有很大的局限性,JavaScript要调用原生方法通常需要约定好协议之后通过Request来传递