rac-Framework Overview

Source: Internet
Author: User

Flow (Racstream): A stream represents a sequence of multiple object values, which can either be current or appear in the future, but must be retrieved successively sequentially.

Signal (racsignal): signal is a push-type stream, the signal can be subscribed to pass events to subscribers, there are three main types of events: Next,error,complete. Next can carry a normal value object, the error indicates that an exception occurred and the Nserror object is passed, and completed indicates a successful end. Multiple next events can be emitted in the life cycle of the signal, followed by an error event or a complete event.

Subscriber (Racsubscriber): When a subscription interface such as subscribeNext:error:completed is used for a signal, the RAC implicitly generates a subscriber. The subscriber holds the signal until the signal has an error or complete event, and the Subscriber is automatically cleaned out.

Theme (Racsubject): A topic is a flexible signal that can be used to send next events regardless of whether a subscriber exists

Commands

A command, represented by the Raccommand class, creates and subscribes to a signal on response to some action. This makes is the 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 is automatically disabled based on a signal, and this disabled state can be represented in a UI by Disab Ling any controls associated with the command.

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

Connections

A connection, represented by the Racmulticastconnection class, are a subscription that's shared between any Numbe R of Subscribers.

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

A connection is created through -publish the or -multicast: methods on racsignal, and ensures this 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 being hot, and the underlying subscription would remain active UNT Il All subscriptions to the connection is disposed.

Sequences

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

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

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

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

Disposables

The racdisposable class is used for cancellation and resource cleanup.

Disposables is most commonly used to unsubscribe from a signal. When a subscription is disposed, the corresponding subscriber won't receive any further events from the signal . Additionally, associated with the subscription (background processing, network requests, etc.) would be cancelled, Since the results is no longer needed.

For more information on cancellation, see the RAC Design guidelines.

Schedulers

A scheduler, represented by the Racscheduler class, was a serial execution queue for signals to perform W Ork or deliver their results upon.

Schedulers is similar to Grand central Dispatch queues, but schedulers support cancellation (via disposables), and always Execute serially. With the exception of the +immediatescheduler, schedulers does not offer synchronous execution. This helps avoid deadlocks, and encourages the use of signal operators instead of blocking work.

Racscheduler is also somewhat similar NSOperationQueue to, but schedulers does not allow tasks to being 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 The 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.

rac-Framework Overview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.