Skip to content

Commit

Permalink
Disposed by Array[Any].
Browse files Browse the repository at this point in the history
  • Loading branch information
lm2343635 committed Apr 22, 2019
1 parent 37e3f1e commit f4636f0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Example/RxBinding/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@ class ViewController: UIViewController {
view.addSubview(characterCountLabel2)
createConstraints()

disposeBag ~ [
viewModel.text <~> textFeild.rx.text,
viewModel.uppercaseText ~> label.rx.text,
viewModel.charactersCount ~> [characterCountLabel1, characterCountLabel2].map { $0.rx.text }
]

/**
disposeBag
~ viewModel.text <~> textFeild.rx.text
~ viewModel.uppercaseText ~> label.rx.text
~ viewModel.charactersCount ~> [characterCountLabel1, characterCountLabel2].map { $0.rx.text }
*/

/**
viewModel.text <~> textFeild.rx.text ~
Expand Down
23 changes: 22 additions & 1 deletion RxBinding/Classes/DisposedBy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,32 @@ extension DisposeBag {
disposable.disposed(by: disposeBag)
}

@discardableResult public static func ~ (disposeBag: DisposeBag, disposable: Disposable) -> DisposeBag {
@discardableResult
public static func ~ (disposeBag: DisposeBag, disposable: Disposable) -> DisposeBag {
disposable.disposed(by: disposeBag)
return disposeBag
}

public static func ~ (disposeBag: DisposeBag, disposables: [Any]) {
disposables.map { obj -> [Disposable] in
switch obj.self {
case is Disposable:
return [obj as! Disposable]
case is [Disposable]:
return obj as! [Disposable]
default:
return []
}
}.reduce([]) { $0 + $1 }.forEach {
print($0)
$0.disposed(by: disposeBag)
}
}

public static func ~ (disposables: [Any], disposeBag: DisposeBag) {
disposeBag ~ disposables
}

}

extension Array where Element == Disposable {
Expand Down

0 comments on commit f4636f0

Please sign in to comment.