TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Dec 2015 |
SPMSupports SPM | ✗ |
Maintained by Pedro Piñera.
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.
git clone https://github.com/swiftreactive/ReactiveCommander
brew install carthage
carthage update
ReactiveCommander.xcodeproj
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.
public func action() throws -> T
method.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.Command
and CommandQueue
s:
let disposable = queue <~ command
- Enqueues the command and return the disposable.Command
s actions must be synchronous. The asynchrony is handled by the queue.Command
s must represent isolated operations and complex relations between them should be avoided.ReactiveCommander is available under the MIT license. See the LICENSE file for more info.