-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bind observable to collection of observers #166
Closed
Closed
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7dfc999
added new bind(to: [ObserverType]) operator to bind an observable to …
6a760c3
attempt at playground page
f5cf18d
Made extension public so its available outside of the module
freak4pc 1366173
Added bind(to: O...) variadic option
freak4pc 4994418
Added variadic sample in Playground
freak4pc 8c95a43
renamed files, added drive(_:) overload
ee3f78e
tests now testing disposable, updated playground
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
41 changes: 41 additions & 0 deletions
41
Playground/RxSwiftExtPlayground.playground/Pages/driveMany.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*: | ||
> # IMPORTANT: To use `RxSwiftExtPlayground.playground`, please: | ||
|
||
1. Make sure you have [Carthage](https://github.com/Carthage/Carthage) installed | ||
1. Fetch Carthage dependencies from shell: `carthage bootstrap --platform ios` | ||
1. Build scheme `RxSwiftExtPlayground` scheme for a simulator target | ||
1. Choose `View > Show Debug Area` | ||
*/ | ||
|
||
//: [Previous](@previous) | ||
import UIKit | ||
import RxSwift | ||
import RxCocoa | ||
import RxSwiftExt | ||
|
||
/*: | ||
## drive(_: Collection) | ||
|
||
The `drive(_: Collection)` operator drives a collection of observers. | ||
*/ | ||
|
||
example("Drive a collection of observers") { | ||
let textField1 = UITextField() | ||
let textField2 = UITextField() | ||
let textField3 = UITextField() | ||
let isEditableStream = Driver.of(true, false, false, true) | ||
|
||
textField1.rx.observeWeakly(Bool.self, "enabled").debug("textField1").subscribe() | ||
textField2.rx.observeWeakly(Bool.self, "enabled").debug("textField2").subscribe() | ||
textField3.rx.observeWeakly(Bool.self, "enabled").debug("textField3").subscribe() | ||
|
||
isEditableStream.debug().drive([textField1.rx.isEnabled, | ||
textField2.rx.isEnabled, | ||
textField3.rx.isEnabled]) | ||
|
||
isEditableStream.debug().drive(textField1.rx.isEnabled, | ||
textField2.rx.isEnabled, | ||
textField3.rx.isEnabled) | ||
} | ||
|
||
//: [Next](@next) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// driveMany+RxCocoa.swift | ||
// RxSwiftExt | ||
// | ||
// Created by Matthew Crenshaw on 7/19/18. | ||
// Copyright © 2018 RxSwift Community. All rights reserved. | ||
// | ||
|
||
import RxSwift | ||
import RxCocoa | ||
|
||
public extension SharedSequenceConvertibleType where SharingStrategy == DriverSharingStrategy { | ||
|
||
/** | ||
Creates new shared subscriptions and sends elements to collection of observers. | ||
This method can be only called from `MainThread`. | ||
|
||
- parameter to: Collection of observers that receives events. | ||
- returns: Disposable object that can be used to unsubscribe the observers. | ||
*/ | ||
func drive<O: ObserverType>(_ observers: [O]) -> Disposable where Self.E == O.E { | ||
let disposables = observers.map(self.drive(_:)) | ||
return CompositeDisposable(disposables: disposables) | ||
} | ||
|
||
/** | ||
Creates new shared subscriptions and sends elements to collection of observers. | ||
This method can be only called from `MainThread`. | ||
|
||
- parameter to: Collection of observers that receives events. | ||
- returns: Disposable object that can be used to unsubscribe the observers. | ||
*/ | ||
func drive<O: ObserverType>(_ observers: O...) -> Disposable where Self.E == O.E { | ||
return drive(observers) | ||
} | ||
} |
7 changes: 3 additions & 4 deletions
7
...RxCocoa/BindCollectionTests+RxCocoa.swift → Tests/RxCocoa/BindManyTests+RxCocoa.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be bindMany like the other places.