-
Notifications
You must be signed in to change notification settings - Fork 211
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 #163
Comments
Uhm this is actually very interesting :) Still could be possibly useful. Any feedback from @RxSwiftCommunity/contributors would be super-helpful here. The overload of disposing many Disposable(s) together might also be useful in general - But might be better to use |
I agree with @freak4pc extension ObservableType {
func bind<O>(to observers: [O]) -> Disposable where O : ObserverType, Self.E == O.E {
let shared = self.share()
let disposables = observers.map(shared.bind(to:))
return CompositeDisposable(disposables: disposables)
}
} |
There was recently a PR on RxSwift to take care of disposables in one call: |
Oh I wasn't aware of CompositeDisposable. I'll update my gist! |
@valerianb that is also a cool PR (the You would still need to repeat the binding (a.bind(to: b), a.bind(to:c)), instead of a.bind(to: [b, c])). So when thinking about this the last few days I think this could be a great addition if you'd like to build it @sgtsquiggs and push a PR so I can review, with tests, etc. |
Closing, cause issue was resolved with RxSwift 5.0 |
Name and description
An extension on ObservableType to allow
.bind(to:)
with a collection of observers, and an extension on Collection (where Iterator.Element == Disposable) to allow.disposed(by:)
with a collection of Disposables.Motivation for inclusion
Useful when you have a single observable binding to a lot of observers. A big use case is when implementing forms and having a single observable bind to isEnabled on a multitude of controls.
Example of use
Implementation here: https://gist.github.com/sgtsquiggs/0b1dc9dbd6fe51f107d4082ac7c448cd
The text was updated successfully, but these errors were encountered: