ReactiveCommand 1.0.0

ReactiveCommand 1.0.0

Maintained by MaskBlurView.



 
Depends on:
RxSwift~> 4.0
RxCocoa~> 4.0
 

  • By
  • kjisoo

ReactiveCommand

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Creation ReactiveCommand

// use closure
let command = ReactiveCommand<InputType, OutputType>(execute: (InputType) -> OutputType, canExecute: Observable<Bool>)

// transform observable
let loadMoreCommand = ReactiveCommand<Int, Post>(execute: postService.load)

// combined command
// The Input Type must be the same.
// OutputType does not matter.
let removeA = ReactiveCommand<Void, Void>(execute...)
let removeB = ReactiveCommand<Void, Void>(execute...)
let removeC = ReactiveCommand<Void, Void>(execute...)
let removeAllCommand = ReactiveCommand.combined(with: removeA.asCommandExecuter(), removeB.asCommandExecuter(), removeC.asCommandExecuter())

Subscribe

let command = ReactiveCommand<Input, Output>.init(...)
command.subscribe(onNext: { Output in
    // something
})

Binding

let saveCommand = ReactiveCommand<Void, Output).init(...)
var saveButton: UIButton
saveButton.bind(to: saveCommand.asCommandExecuter()).disposed(by: disposeBag)

// Binding with TextField like passcode
let passCommand = ReactiveCommand<String, Void>(execute: { (code) in
    // code
})
let combinedEexecutor = passCommand.combined(with: textField.rx.text.orEmpty.asObservable())
doneButton.bind(to: combinedEexecutor).disposed(by: disposeBag)

Requirements

  • swift 4.2

Installation

ReactiveCommand is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ReactiveCommand'

Author

kjisoo, [email protected]

License

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