Skip to content

Commit

Permalink
Clean unneeded multi-bind code in Observable
Browse files Browse the repository at this point in the history
  • Loading branch information
freak4pc committed Oct 6, 2020
1 parent dc3aebb commit 7e7a32a
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions RxCocoa/Common/Observable+Bind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ extension ObservableType {
- returns: Disposable object that can be used to unsubscribe the observers.
*/
public func bind<Observer: ObserverType>(to observers: Observer...) -> Disposable where Observer.Element == Element {
return self.bind(to: observers)
return self.subscribe { event in
observers.forEach { $0.on(event) }
}
}

/**
Expand All @@ -28,20 +30,10 @@ extension ObservableType {
- returns: Disposable object that can be used to unsubscribe the observers.
*/
public func bind<Observer: ObserverType>(to observers: Observer...) -> Disposable where Observer.Element == Element? {
self.map { $0 as Element? }.bind(to: observers)
}

/**
Creates new subscription and sends elements to observer(s).
In this form, it's equivalent to the `subscribe` method, but it better conveys intent, and enables
writing more consistent binding code.
- parameter to: Observers to receives events.
- returns: Disposable object that can be used to unsubscribe the observers.
*/
private func bind<Observer: ObserverType>(to observers: [Observer]) -> Disposable where Observer.Element == Element {
self.subscribe { event in
observers.forEach { $0.on(event) }
}
return self.map { $0 as Element? }
.subscribe { event in
observers.forEach { $0.on(event) }
}
}

/**
Expand Down

0 comments on commit 7e7a32a

Please sign in to comment.