ReactiveCommander 0.0.4

ReactiveCommander 0.0.4

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Dec 2015
SPMSupports SPM

Maintained by Pedro Piñera.



  • By
  • @pepibumur

Requirements

Installation

CocoaPods

You can install ReactiveCommander using CocoaPods adding the following lines to your Podfile:

use_frameworks!
pod "ReactiveCommander/RX" // For RxSwift
pod "ReactiveCommander/RAC" // For ReactiveCocoa

Wherever you want to use the framework import it with import ReactiveCommander

Carthage

It's also available to install using Carthage

github "SwiftReactive/ReactiveCommander"

Depending on the framework you want to use ReactiveCocoa or RxSwift you'll have to add to your project, RACCommander or RXCommander respectively. Then import them with these names.

Contribute

  • Git clone the repository: git clone https://github.com/swiftreactive/ReactiveCommander
  • Install Carthage: brew install carthage
  • Update Carthage dependencies: carthage update
  • Open the project ReactiveCommander.xcodeproj

Components

ReactiveCommander implements the programming command pattern using NSOperationQueue and a Reactive approach. The idea of that pattern is encapsulating operations in command that are initialized with the required parameters to executed the action. These commands can be scheduled in a queue that will manage the threading, concurrency and execution of these commands.

Command

  • Command: Default generic command where T is the returned type. This command has to be overriden before being used implementing the public func action() throws -> T method.

CommandQueue

  • Commands can be enqueued in the CommandQueue which is a subclass of NSOperationQueue with a new method:

    // ReactiveCocoa
    func addCommand<T, E: ErrorType>(cmd: Command<T, E>) -> SignalProducer<T, E>
    
    // RxSwift
    public func addCommand<T>(cmd: Command<T>) -> Observable<T>

    When the SignalProducer is started or the Observable gets a subscriber, the command is added to the queue in order to be executed.

  • CommandQueue provides a singleton instance that can be accessed with CommandQueue.backgroundQueue. If you want to implement your own queue with your own NSOperationQueue configuration you can just subclass this class.
  • ReactiveCommander provides a custom operator to be used with Command and CommandQueues:
    • let disposable = queue <~ command - Enqueues the command and return the disposable.

Notes

  • Commands actions must be synchronous. The asynchrony is handled by the queue.
  • Commands must represent isolated operations and complex relations between them should be avoided.

License

ReactiveCommander is available under the MIT license. See the LICENSE file for more info.