Latest 1.0.0
Homepage https://github.com/kjisoo/ReactiveCommand
License MIT
Platforms ios 8.0
Dependencies RxSwift, RxCocoa
Authors

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.

Latest podspec

{
    "name": "ReactiveCommand",
    "version": "1.0.0",
    "summary": "Command available in MVVM.",
    "description": "You can use the ReactiveCommand to distinguish commands and properties in a ViewModel.nCommand executes the closure statement or switches Observable.nCommand can be created by combining multiple commands.nCommand can be used by binding to Cocoa Component.",
    "homepage": "https://github.com/kjisoo/ReactiveCommand",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "kjisoo": "[email protected]"
    },
    "source": {
        "git": "https://github.com/kjisoo/ReactiveCommand.git",
        "tag": "1.0.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "swift_version": "4.2",
    "source_files": "ReactiveCommand/Classes/**/*",
    "dependencies": {
        "RxSwift": [
            "~> 4.0"
        ],
        "RxCocoa": [
            "~> 4.0"
        ]
    }
}

Pin It on Pinterest

Share This