ReactiveCommand 1.0.0

ReactiveCommand 1.0.0

MaskBlurView 维护。



 
依赖
RxSwift~> 4.0
RxCocoa~> 4.0
 

  • 作者
  • kjisoo

ReactiveCommand

CI Status Version License Platform

示例

要运行示例项目,先克隆仓库,然后从示例目录运行 pod install

创建 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())

订阅

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

绑定

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)

要求

  • swift 4.2

安装

ReactiveCommand 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'ReactiveCommand'

作者

kjisoo, [email protected]

许可

ReactiveCommand 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。