Skip to content

You can use the ReactiveCommand to distinguish commands and properties in a ViewModel.

License

Notifications You must be signed in to change notification settings

kjisoo/ReactiveCommand

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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, kim@jisoo.net

License

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

About

You can use the ReactiveCommand to distinguish commands and properties in a ViewModel.

Resources

License

Stars

Watchers

Forks

Packages

No packages published