Closed mpsnp closed 4 years ago
Warnings | |
---|---|
:warning: | It looks like code was changed without adding anything to the Changelog. If this is a trivial PR that doesn't need a changelog, add #trivial to the PR title or body. |
Generated by :no_entry_sign: dangerJS
Hey @mpsnp - Thanks for your contribution.
Is this really different then withUnretained
+ subscribe ? I'd prefer not add more operators unless needed.
Ok, here is my explanation:
withUnretained
+ subscribe
only works for Observable
, so shared sequences should be converted to Observable
first, loosing their original types, which is not good i guessObservable
which do exactly the same as in this PR.state // Usually Driver
.asObservable()
.withUnretained(self)
.subscribe(onNext: { controller, state in
controller.render(state: state)
})
.disposed(by: disposeBag)
with
state
.drive(weak: self, onNext: Controller.render)
.disposed(by: disposeBag)
@freak4pc @MortyMerr any feedback? Actually this is not "new" operator, it already exists here but only for ObservableType
. I just wanted to add it to SharedSequence
. IMHO withUnretained
also should be added to Traits, what do you think?
Please also note this PR with corresponding issue https://github.com/RxSwiftCommunity/RxSwiftExt/pull/219
For me subscribe(weak: self, onNext: ...)
and withUnretanied(self).subscribe(onNext:)
purpose looks absolutely the same.
I think that these operators should be merged into one (for all traits). One operator for weakly referencing an object in subscription block is more than enough.
I prefer withUnretained
, cause it is more generic. It can be used not only with subscription, but with map
, do
etc.
subscribe(weak:
is too specific case, I think it's senseless to have own wrapper for all RxSwift operators (do(weak:
, map(weak:
, filter(weak:
)
What do you think?
I'm siding with Anton here — I'm seeing very little value adding a bunch of do something with weak object overloads when we have withUnretained
that solves all of these cases. Yes, there is an existing subscribe(onNext:)
but it precedes withUnretained
by a years, probably :) There's no reason to deprecate it since it's already in the library, but there's no reason to add more of it with a better solution available.
Currying-style doesn't seem like a good enough reason (to me) to add a bunch of these overloads.
What we actually can do is to add withUnretained for all traits
This pull request adds both Signal & Driver weak subscriptions.