Skip to content
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

Add new subscribe/drive/emit with object, Deprecate withUnretained on Driver #2290

Merged
merged 11 commits into from
Feb 10, 2021

Conversation

freak4pc
Copy link
Member

@freak4pc freak4pc commented Feb 8, 2021

tl;dr

This PR will:

  1. Hard deprecate withUnretained for Driver specifically
  2. Update documentation for the other implementations of withUnretained so it’s obvious to look out for replaying behavior
  3. Add new subscribe(with:onNext:etc:) operators for all items: Observable, Driver, Signal, Infallible, Completable, Single, Maybe.

Why are we doing this?

RxSwift 6.0 added a new withUnretained operator that creates a weak reference and then retains it within the next emission, so you could do observable.withUnretained(self) and get self with the element in parity.

Unfortunately there is a small side-effect we didn't consider. If the stream you're working with has share(replay: 1), the replay buffer would buffer self along with the value, which might create a retain cycle in some scenarios.

This in itself isn't an issue (just a documentation change), but for Driver specifically, the default is to replay the latest value, so we are forced to immediately deprecated withUnretained on Driver, specifically. It is still available on all other traits, Observable and Signal.

This is a very rare decision, to deprecate something in a patch release, but given this is a very new API, we prefer to deprecate it ASAP, before any widespread adoption.

Along with this deprecate, we're adding a new set of APIs to have a similar action for different pieces. For Driver, this looks like this:

driver
  .drive(with: self,
         onNext: { object, value in ... 
           // object is self, value is the emission from `driver`
         })

This API is more concise and is available for all pieces in RxSwift and RxCocoa: Observable, Infallible, Driver, Signal, Completable, Single, and Maybe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant