Add better API for Disposable when adding to DisposeBag #1079
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.
Added
I brought up in the Slack channel that the original Disposable API
.addDisposableTo(_ bag: DisposeBag)
felt out of line with the newly minted Swift API guidelines.Because an
Observable
returns aDisposable
after using thesubscribe
API, it makes no sense to treat theDisposable
API like it's anObservable
.After some discussion in the channel, the group generally favored
disposed(by bag: DisposeBag)
to eventually replaceaddDisposableTo
, which is why we've created it as an extension for the time being. People will be able to slowly transition from the old API to the new without being under duress.The new APIs implementation is merely a wrapper around the old. I wrote it this way because I felt keeping one implementation of it would be beneficial, at least until the old one gets deprecated (if it ever will).
Old API
.addToDisposeBag(disposeBag)
New APU
.disposed(by: disposeBag)